diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 64e4f53..02d560a 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -94,7 +94,10 @@ async function fetchJson(path, signal) { signal, headers: { Accept: 'application/json' }, }) - const body = await response.json().catch(() => null) + const contentType = response.headers.get('content-type') || '' + const body = contentType.includes('application/json') + ? await response.json().catch(() => null) + : null if (!response.ok) { const error = new Error(body?.error || `Request failed with ${response.status}`) @@ -103,6 +106,14 @@ async function fetchJson(path, signal) { throw error } + if (!body) { + const error = new Error(`Expected JSON from ${path}`) + error.status = response.status + error.path = path + error.contentType = contentType + throw error + } + return body } @@ -115,7 +126,7 @@ async function fetchPublicJson(source, signal) { return await fetchJson(source.staticPath, signal) } catch (error) { if (signal?.aborted || error?.name === 'AbortError') throw error - if (error?.status === 404) missingStaticDataPaths.add(source.staticPath) + if (error?.status === 404 || error?.contentType) missingStaticDataPaths.add(source.staticPath) return fetchJson(source.apiPath, signal) } }