mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Replace strip-json-comments with jsonc-parser for better error reporting
This commit is contained in:
1 parent
e1890d0554
commit
e1a4a70d3d
13 files changed
+132
-34
No files matched your search
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user