(err: unknown)
| 1 | import { isPlainObject } from "./plainObject"; |
| 2 | |
| 3 | export function error2String(err: unknown): string { |
| 4 | if (!err) return ""; |
| 5 | if (typeof err === "string") { |
| 6 | return err; |
| 7 | } |
| 8 | if (err instanceof Error) { |
| 9 | return `${err.name}: ${err.message}`; |
| 10 | } |
| 11 | if (isPlainObject(err)) { |
| 12 | const key = ["message", "msg", "error", "err_msg", "error_message"]; |
| 13 | for (const k of key) { |
| 14 | const v = err[k]; |
| 15 | if (typeof v === "string") return v; |
| 16 | } |
| 17 | } |
| 18 | return JSON.stringify(err); |
| 19 | } |
nothing calls this directly
no test coverage detected