Skip to content

Commit d2cf8b6

Browse files
committed
fix(admin): parse error responses more resiliently in useCreateSandbox
1 parent e97cb9d commit d2cf8b6

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

apps/admin/src/hooks/use-simulate.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ export function useCreateSandbox() {
4646
body: JSON.stringify(params),
4747
})
4848
if (!res.ok) {
49-
const data = (await res.json().catch(() => ({ error: 'Request failed' }))) as { error: string }
50-
throw new Error(data.error)
49+
const text = await res.text()
50+
let msg = `Request failed (${res.status})`
51+
try {
52+
const data = JSON.parse(text) as { error?: string }
53+
if (data.error) msg = data.error
54+
} catch {
55+
if (text.length > 0) msg = text.slice(0, 500)
56+
}
57+
throw new Error(msg)
5158
}
5259
return res.json() as Promise<SandboxResult>
5360
},

0 commit comments

Comments
 (0)