| 1234567891011121314151617181920212223242526272829303132 |
- import axios from "axios";
- enum HttpError {
- Unauthorized = 401,
- ServerError = 500,
- }
- type ErrorHandlerResponse = {
- status: HttpError;
- message: string;
- };
- export const errorHandler = (error: unknown): ErrorHandlerResponse => {
- if (axios.isAxiosError(error) && error.response) {
- const { status, data } = error.response;
- console.log(status, data);
- if (
- status === HttpError.ServerError &&
- data?.message.includes("Incorect")
- ) {
- return {
- status: HttpError.Unauthorized,
- message: "The email or password was incorrect",
- };
- }
- return { status, message: data };
- }
- return {
- status: HttpError.ServerError,
- message: "There was an error, please try again",
- };
- };
|