(error: unknown, fallback: string)
| 11 | * then `fallback`. |
| 12 | */ |
| 13 | export function getApiErrorMessage(error: unknown, fallback: string): string { |
| 14 | const body = axios.isAxiosError(error) |
| 15 | ? error.response?.data |
| 16 | : error instanceof Error && "response" in error |
| 17 | ? (error as { response?: unknown }).response |
| 18 | : undefined; |
| 19 | |
| 20 | if (body && typeof body === "object") { |
| 21 | const { message, detail } = body as { |
| 22 | message?: unknown; |
| 23 | detail?: unknown; |
| 24 | }; |
| 25 | if (typeof message === "string" && message) return message; |
| 26 | if (typeof detail === "string" && detail) return detail; |
| 27 | } |
| 28 | |
| 29 | if (error instanceof Error && error.message) return error.message; |
| 30 | return fallback; |
| 31 | } |
no outgoing calls
no test coverage detected