(error: unknown)
| 1 | export function normalizeErrorMessage(error: unknown): string { |
| 2 | if (error instanceof Error) return error.message; |
| 3 | if (typeof error === "string") return error; |
| 4 | if (typeof error === "object" && error !== null) { |
| 5 | const msg = (error as Record<string, unknown>).message; |
| 6 | if (typeof msg === "string") return msg; |
| 7 | try { |
| 8 | return JSON.stringify(error); |
| 9 | } catch { |
| 10 | try { |
| 11 | return `{${Object.keys(error as object).join(", ")}}`; |
| 12 | } catch { |
| 13 | /* truly opaque object */ |
| 14 | } |
| 15 | } |
| 16 | } |
| 17 | return String(error ?? "unknown error"); |
| 18 | } |
no outgoing calls
no test coverage detected