(error: unknown, fallback: string)
| 22 | * then `fallback`. |
| 23 | */ |
| 24 | export function getApiErrorMessage(error: unknown, fallback: string): string { |
| 25 | const body = getApiErrorBody(error); |
| 26 | |
| 27 | if (body && typeof body === "object") { |
| 28 | const { message, detail } = body as { |
| 29 | message?: unknown; |
| 30 | detail?: unknown; |
| 31 | }; |
| 32 | if (typeof message === "string" && message) return message; |
| 33 | if (typeof detail === "string" && detail) return detail; |
| 34 | } |
| 35 | |
| 36 | if (error instanceof Error && error.message) return error.message; |
| 37 | return fallback; |
| 38 | } |
no test coverage detected