🔄 Refactor error handling and state reset logic for improved clarity and consistency in tournament management
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user