MCPcopy Index your code
hub / github.com/anomalyco/opencode / parseWrappedError

Function parseWrappedError

packages/opencode/src/plugin/openai/ws.ts:342–360  ·  view source on GitHub ↗
(event: Record<string, unknown> | undefined, body: string)

Source from the content-addressed store, hash-verified

340}
341
342function 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
362function cancelError(reason: unknown) {
363 if (isAbortError(reason)) return reason

Callers 1

onMessageFunction · 0.85

Calls 1

isRecordFunction · 0.90

Tested by

no test coverage detected