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