Files
maher 511fad8199
Build / run (push) Has been cancelled
Initial commit
2026-05-14 13:42:10 +02:00

19 lines
514 B
TypeScript
Executable File

import axios from 'axios';
import {BackendErrorResponse} from '../../errors/backend-error-response';
export function getAxiosErrorMessage(
err: unknown,
field?: string | null
): string | undefined {
if (axios.isAxiosError(err) && err.response) {
const response = err.response.data as BackendErrorResponse;
if (field != null) {
const fieldMessage = response.errors?.[field];
return Array.isArray(fieldMessage) ? fieldMessage[0] : fieldMessage;
}
return response?.message;
}
}