fix: check response.ok before parsing JSON in fetch calls

Fix JSON parsing errors when server returns non-JSON responses:
- Check response.ok before calling response.json()
- Add fallback error messages using status text
- Apply fix to all fetch calls across 12 components

This prevents 'JSON.parse: unexpected character' errors when
server returns HTML error pages or other non-JSON responses.
This commit is contained in:
2026-04-03 19:27:10 -07:00
parent 9b15d7e61f
commit 37eb1f8e21
12 changed files with 812 additions and 226 deletions
+10
View File
@@ -26,6 +26,16 @@ export function DeleteTournamentButton({ tournamentId, tournamentName, matchCoun
}),
})
if (!response.ok) {
try {
const errorData = await response.json()
alert(`Error: ${errorData.error || 'Failed to delete tournament'}`)
} catch {
alert(`Error: ${response.status} ${response.statusText}`)
}
return
}
const data = await response.json()
if (data.success) {