🔄 Refactor error handling and state reset logic for improved clarity and consistency in tournament management

This commit is contained in:
2026-01-29 02:03:45 +00:00
parent 6835e3a7b8
commit fb2629334c

View File

@@ -682,49 +682,13 @@ async function toggleTournamentDetails(tournamentId) {
} }
} }
function handleError(err) {
console.error('Challonge API Error:', err);
if (err.errors && Array.isArray(err.errors)) {
// JSON:API error format (v2.1) - already formatted
error.value = err.errors;
} else if (err.status) {
// HTTP error with status code
error.value = [
{
status: err.status,
message: err.message || 'Unknown error',
field: null
}
];
} else if (err.message) {
// Generic error with message
error.value = [
{
status: 'Error',
message: err.message,
field: null
}
];
} else {
// Fallback for unknown error formats
error.value = [
{
status: 'Error',
message: 'An unexpected error occurred. Check console for details.',
field: null
}
];
}
}
async function switchApiVersion() { async function switchApiVersion() {
// Clear state when switching versions // Clear state when switching versions
tournaments.value = null; tournamentListState.reset();
error.value = null; loadMoreState.reset();
tournamentDetailsState.reset();
searchQuery.value = ''; searchQuery.value = '';
expandedTournamentId.value = null; expandedTournamentId.value = null;
tournamentDetails.value = null;
currentPage.value = 1; currentPage.value = 1;
} }