(maybeError)
| 3 | } |
| 4 | |
| 5 | const toErrorWithMessage = (maybeError) => { |
| 6 | if (isErrorWithMessage(maybeError)) return maybeError |
| 7 | |
| 8 | try { |
| 9 | return new Error(JSON.stringify(maybeError)) |
| 10 | } catch { |
| 11 | // fallback in case there's an error stringifying the maybeError |
| 12 | // like with circular references for example. |
| 13 | return new Error(String(maybeError)) |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | export const getErrorMessage = (error) => { |
| 18 | return toErrorWithMessage(error).message |
no test coverage detected