(e: unknown)
| 1 | export function errorToString(e: unknown) { |
| 2 | if (e === null) return "" |
| 3 | |
| 4 | if (e === undefined) return "" |
| 5 | |
| 6 | if (e instanceof Error) { |
| 7 | return e.message |
| 8 | } |
| 9 | |
| 10 | if (typeof e === "string") { |
| 11 | return e |
| 12 | } |
| 13 | |
| 14 | if (typeof e === "object") { |
| 15 | if ("error" in e && typeof e.error == "string") { |
| 16 | return e.error |
| 17 | } else if ("message" in e && typeof e.message === "string") { |
| 18 | return e.message |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | if (e && e.toString) return e.toString() |
| 23 | |
| 24 | return JSON.stringify(e) |
| 25 | } |
no test coverage detected