23 lines
466 B
TypeScript
23 lines
466 B
TypeScript
import { AxiosError } from 'axios';
|
|
|
|
export interface ErrorData {
|
|
success: boolean;
|
|
status_code: number;
|
|
errors: {
|
|
code: unknown;
|
|
message: string;
|
|
}[];
|
|
}
|
|
|
|
export function getErrorMessage(error: AxiosError<ErrorData>): string {
|
|
try {
|
|
if (error.response) {
|
|
return error.response.data.errors.map((err) => err.message).join('\n');
|
|
}
|
|
|
|
return error.message;
|
|
} catch (error) {
|
|
return 'Unknown error, please check devtools.';
|
|
}
|
|
}
|