(e: unknown)
| 211 | * axios.isAxiosError()) to keep this module dependency-free. |
| 212 | */ |
| 213 | export function classifyAxiosError(e: unknown): { |
| 214 | kind: AxiosErrorKind |
| 215 | status?: number |
| 216 | message: string |
| 217 | } { |
| 218 | const message = errorMessage(e) |
| 219 | if ( |
| 220 | !e || |
| 221 | typeof e !== 'object' || |
| 222 | !('isAxiosError' in e) || |
| 223 | !e.isAxiosError |
| 224 | ) { |
| 225 | return { kind: 'other', message } |
| 226 | } |
| 227 | const err = e as { |
| 228 | response?: { status?: number } |
| 229 | code?: string |
| 230 | } |
| 231 | const status = err.response?.status |
| 232 | if (status === 401 || status === 403) return { kind: 'auth', status, message } |
| 233 | if (err.code === 'ECONNABORTED') return { kind: 'timeout', status, message } |
| 234 | if (err.code === 'ECONNREFUSED' || err.code === 'ENOTFOUND') { |
| 235 | return { kind: 'network', status, message } |
| 236 | } |
| 237 | return { kind: 'http', status, message } |
| 238 | } |
| 239 |
no test coverage detected