(err: unknown)
| 58 | * since axios's default message only includes the status code. |
| 59 | */ |
| 60 | export function describeAxiosError(err: unknown): string { |
| 61 | const msg = errorMessage(err) |
| 62 | if (err && typeof err === 'object' && 'response' in err) { |
| 63 | const response = (err as { response?: { data?: unknown } }).response |
| 64 | if (response?.data && typeof response.data === 'object') { |
| 65 | const data = response.data as Record<string, unknown> |
| 66 | const detail = |
| 67 | typeof data.message === 'string' |
| 68 | ? data.message |
| 69 | : typeof data.error === 'object' && |
| 70 | data.error && |
| 71 | 'message' in data.error && |
| 72 | typeof (data.error as Record<string, unknown>).message === |
| 73 | 'string' |
| 74 | ? (data.error as Record<string, unknown>).message |
| 75 | : undefined |
| 76 | if (detail) { |
| 77 | return `${msg}: ${detail}` |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | return msg |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Extract the HTTP status code from an axios error, if present. |
no test coverage detected