(response: Response)
| 94 | } |
| 95 | |
| 96 | async function runtimeApiError(response: Response): Promise<RuntimeApiError> { |
| 97 | const text = await response.text(); |
| 98 | try { |
| 99 | const body = JSON.parse(text) as { error?: unknown }; |
| 100 | if (typeof body.error === "string") { |
| 101 | return new RuntimeApiError(response.status, body.error, body.error); |
| 102 | } |
| 103 | if (isRecord(body.error)) { |
| 104 | const code = typeof body.error.code === "string" ? body.error.code : "unknown_error"; |
| 105 | const message = typeof body.error.message === "string" ? body.error.message : code; |
| 106 | return new RuntimeApiError(response.status, code, message); |
| 107 | } |
| 108 | } catch { |
| 109 | // Preserve useful server text when a non-conforming response reaches the client. |
| 110 | } |
| 111 | return new RuntimeApiError(response.status, "unknown_error", text || response.statusText); |
| 112 | } |
| 113 | |
| 114 | export function parseSse(body: string): RuntimeEvent[] { |
| 115 | return body |
no test coverage detected