ai generated solutions to our ai generated problems

This commit is contained in:
2026-06-19 23:58:50 +01:00
parent 07b087e7df
commit 736fe40e75
+13 -2
View File
@@ -94,7 +94,10 @@ async function fetchJson(path, signal) {
signal, signal,
headers: { Accept: 'application/json' }, 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) { if (!response.ok) {
const error = new Error(body?.error || `Request failed with ${response.status}`) const error = new Error(body?.error || `Request failed with ${response.status}`)
@@ -103,6 +106,14 @@ async function fetchJson(path, signal) {
throw error 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 return body
} }
@@ -115,7 +126,7 @@ async function fetchPublicJson(source, signal) {
return await fetchJson(source.staticPath, signal) return await fetchJson(source.staticPath, signal)
} catch (error) { } catch (error) {
if (signal?.aborted || error?.name === 'AbortError') throw 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) return fetchJson(source.apiPath, signal)
} }
} }