fix(sdk): wrap thrown error bodies in Error
SDK throwOnError paths now convert structured response bodies into real Error instances while preserving the original body and status in cause.
This commit is contained in:
parent
ba9e4b67ed
commit
11363170ca
1 changed files with 138 additions and 20 deletions
|
|
@ -394,8 +394,16 @@ describe("HttpApi SDK", () => {
|
|||
const missing = yield* capture(() => sdk.session.get({ sessionID }))
|
||||
const thrown = yield* captureThrown(() => sdk.session.get({ sessionID }, { throwOnError: true }))
|
||||
|
||||
// Result-tuple path: error body is preserved as-is so existing
|
||||
// consumers reading `result.error.name` / `JSON.stringify(error)`
|
||||
// keep working byte-for-byte.
|
||||
expect(missing.error).toEqual(expected)
|
||||
expect(thrown).toEqual(expected)
|
||||
// throwOnError path: SDK wraps the body in a real Error with the
|
||||
// server's message, with the original parsed body preserved under
|
||||
// `.cause.body`.
|
||||
expect(thrown).toBeInstanceOf(Error)
|
||||
expect((thrown as Error).message).toBe(expected.data.message)
|
||||
expect(((thrown as Error).cause as { body: unknown }).body).toEqual(expected)
|
||||
return {
|
||||
status: missing.status,
|
||||
error: missing.error,
|
||||
|
|
|
|||
Loading…
Reference in a new issue