ai generated solutions to our ai generated problems
This commit is contained in:
+13
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user