(error: unknown)
| 104 | * and plain Error (message). |
| 105 | */ |
| 106 | export function extractErrorMessage(error: unknown): string { |
| 107 | if (!error || typeof error !== "object") |
| 108 | return String(error ?? "Unknown error"); |
| 109 | const e = error as Record<string, unknown>; |
| 110 | // ConnectRPC error |
| 111 | if (typeof e.rawMessage === "string" && e.rawMessage) return e.rawMessage; |
| 112 | // HTTPError (Axios/REST) |
| 113 | const resp = e.response; |
| 114 | if (resp && typeof resp === "object") { |
| 115 | const data = (resp as Record<string, unknown>).data; |
| 116 | if (data && typeof data === "object") { |
| 117 | const msg = (data as Record<string, unknown>).message; |
| 118 | if (typeof msg === "string" && msg) return msg; |
| 119 | } |
| 120 | } |
| 121 | // Plain Error |
| 122 | if (typeof e.message === "string" && e.message) return e.message; |
| 123 | return "Unknown error"; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Extracts an HTTP status code from any error shape. |
no test coverage detected