The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** OpenCode stores `<none>` when it cannot read the provider body. */ |
| 2 | export function readableProviderErrorMessage( |
| 3 | message?: string, |
| 4 | status?: number, |
| 5 | body?: string, |
| 6 | ): string | undefined { |
| 7 | const text = message?.trim() ?? ""; |
| 8 | if (text && text.toLowerCase() !== "<none>") return text; |
| 9 | const title = body |
| 10 | ?.match(/<title[^>]*>([^<]*)<\/title>/i)?.[1] |
| 11 | ?.replace(/\s+/g, " ") |
| 12 | .trim(); |
| 13 | if (title) return typeof status === "number" ? `${title} (HTTP ${status}).` : title; |
| 14 | if (typeof status === "number") return `The model provider failed the request (HTTP ${status}).`; |
| 15 | return text |
| 16 | ? "The model provider failed the request and did not include an error message." |
| 17 | : undefined; |
| 18 | } |