Replace strip-json-comments with jsonc-parser for better error reporting

This commit is contained in:
Chris Scott committed 2026-03-07 10:42:18 -05:00
1 parent e1890d0554
commit e1a4a70d3d
13 files changed
+132 -34

No files matched your search

+22 -1
View File
@@ -8,13 +8,34 @@ interface FetchWrapperOptions extends RequestInit {
params?: Record<string, string | number | boolean | undefined>
}
function formatDetails(details: unknown): string | undefined {
if (Array.isArray(details)) {
return details
.map((d) => {
if (typeof d !== 'object' || d === null) return null
const path = Array.isArray((d as Record<string, unknown>).path)
? ((d as Record<string, unknown>).path as string[])
: undefined
const message = typeof (d as Record<string, unknown>).message === 'string'
? (d as Record<string, unknown>).message as string
: undefined
return path?.length ? `${path.join('.')}: ${message}` : message
})
.filter(Boolean)
.join('; ')
}
if (typeof details === 'string') return details
return undefined
}
async function handleResponse(response: Response): Promise<never> {
const data: ApiErrorResponse = await response.json().catch(() => ({ error: 'An error occurred' }))
const detail = data.detail || formatDetails(data.details)
throw new FetchError(
data.error || 'Request failed',
response.status,
data.code,
data.detail
detail
)
}