(error: unknown)
| 4 | * flag a `String(err)` / `err.toString()` / `${err}` call. |
| 5 | */ |
| 6 | export function getErrorMessage(error: unknown): string { |
| 7 | if (error instanceof Error) { |
| 8 | if (error.cause instanceof Error) { |
| 9 | return `${error.message} (cause: ${error.cause.message})`; |
| 10 | } |
| 11 | |
| 12 | return error.message; |
| 13 | } |
| 14 | |
| 15 | if (typeof error === "string") { |
| 16 | return error; |
| 17 | } |
| 18 | |
| 19 | try { |
| 20 | return JSON.stringify(error); |
| 21 | } catch { |
| 22 | return "Unknown error"; |
| 23 | } |
| 24 | } |
no outgoing calls
no test coverage detected