(maybeError: unknown)
| 9 | } |
| 10 | |
| 11 | const toErrorWithMessage = (maybeError: unknown): ErrorWithMessage => { |
| 12 | if (isErrorWithMessage(maybeError)) return maybeError |
| 13 | |
| 14 | try { |
| 15 | return new Error(JSON.stringify(maybeError)) |
| 16 | } catch { |
| 17 | // fallback in case there's an error stringifying the maybeError |
| 18 | // like with circular references for example. |
| 19 | return new Error(String(maybeError)) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | export const getErrorMessage = (error: unknown) => { |
| 24 | return toErrorWithMessage(error).message |
no test coverage detected