Files
asan-installer-front/src/utility/error-handle.tsx
T
2024-08-26 17:59:20 +03:30

20 lines
721 B
TypeScript

import toast from "react-hot-toast";
export const handleError = (err: any) => {
if (err) {
const errorStatus: number = err?.response?.status;
const keys = errorStatus === 422 ? Object.keys(err?.response?.data.validation) : [];
const handle401Error = () => {
window.localStorage.clear()
window.location.href = "/auth/login"
}
switch (errorStatus) {
case 422: return toast.error(err?.response?.data?.validation[keys[0]]?.msg);
case 401: return handle401Error()
case 500: return toast.error(err?.response?.data?.msg);
default:
return toast.error(err?.response?.data?.msg);
}
}
}