Improve error message formatting and handling in TournamentDetail component

This commit is contained in:
2026-01-29 14:33:12 +00:00
parent f11ca388f8
commit ecf32940ca

View File

@@ -84,7 +84,7 @@ const props = defineProps({
const errorMessage = computed(() => { const errorMessage = computed(() => {
if (!props.error) return ''; if (!props.error) return '';
if (typeof props.error === 'string') return props.error; if (typeof props.error === 'string') return props.error;
// Try to extract useful error info // Try to extract useful error info
const err = props.error; const err = props.error;
if (err.message) { if (err.message) {
@@ -94,17 +94,19 @@ const errorMessage = computed(() => {
} }
return err.message; return err.message;
} }
// Check for response errors // Check for response errors
if (err.response) { if (err.response) {
const status = err.response.status || err.status; const status = err.response.status || err.status;
if (status === 401) return 'Authentication failed. Check your API key.'; if (status === 401) return 'Authentication failed. Check your API key.';
if (status === 403) return 'Access forbidden. You may not have permission to view this tournament.'; if (status === 403)
return 'Access forbidden. You may not have permission to view this tournament.';
if (status === 404) return 'Tournament not found.'; if (status === 404) return 'Tournament not found.';
if (status >= 500) return `Server error (${status}). Please try again later.`; if (status >= 500)
return `Server error (${status}). Please try again later.`;
return `Error ${status}: ${err.response.statusText || 'Request failed'}`; return `Error ${status}: ${err.response.statusText || 'Request failed'}`;
} }
// Fallback // Fallback
return err.toString() || 'An error occurred loading tournament details'; return err.toString() || 'An error occurred loading tournament details';
}); });