Spaces:
Running
Running
File size: 638 Bytes
973dd4c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import { AxiosError } from 'axios';
export function extractErrorMessage(err: unknown, fallback = 'Request failed'): string {
if (err instanceof AxiosError) {
const detail = err.response?.data;
if (detail && typeof detail === 'object' && 'detail' in detail && typeof detail.detail === 'string') {
return detail.detail;
}
return err.message || fallback;
}
if (err instanceof Error) {
return err.message || fallback;
}
return fallback;
}
export function extractErrorStatus(err: unknown): number | undefined {
if (err instanceof AxiosError) {
return err.response?.status;
}
return undefined;
}
|