| 340 | } |
| 341 | |
| 342 | function parseWrappedError(event: Record<string, unknown> | undefined, body: string) { |
| 343 | if (event?.type !== "error") return |
| 344 | const status = event.status ?? event.status_code |
| 345 | if (typeof status !== "number" || (status >= 200 && status < 300)) return |
| 346 | return { |
| 347 | status, |
| 348 | headers: isRecord(event.headers) |
| 349 | ? Object.fromEntries( |
| 350 | Object.entries(event.headers).flatMap(([key, value]) => |
| 351 | typeof value === "string" || typeof value === "number" || typeof value === "boolean" |
| 352 | ? [[key, String(value)]] |
| 353 | : [], |
| 354 | ), |
| 355 | ) |
| 356 | : undefined, |
| 357 | body, |
| 358 | message: isRecord(event.error) && typeof event.error.message === "string" ? event.error.message : `${status}`, |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | function cancelError(reason: unknown) { |
| 363 | if (isAbortError(reason)) return reason |