diff --git a/src/contexts/UserAuthenticationContext.tsx b/src/contexts/UserAuthenticationContext.tsx index 7e1b5db..3b8a7da 100644 --- a/src/contexts/UserAuthenticationContext.tsx +++ b/src/contexts/UserAuthenticationContext.tsx @@ -1,6 +1,8 @@ import authenticateUser, { parseAuthicationErrors } from "@/utils/requests/authenticateUser"; import type { IuserInformations } from "@/utils/requests/types"; -import getUserInformations from "@/utils/requests/userInformations"; +import getUserInformations, { + parseUserInformationsErrors, +} from "@/utils/requests/userInformations"; import ErrorModal from "@components/modals/ErrorModal"; import { LOG } from "@logger"; import AsyncStorage from "@react-native-async-storage/async-storage"; @@ -136,6 +138,9 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac }, onError: (error) => { log.error("userInformationsMutation", error); + const errorString = parseUserInformationsErrors(error); + showModal(); + clearStorages(); }, }); diff --git a/src/utils/requests/userInformations.ts b/src/utils/requests/userInformations.ts index 6b818fc..f533b83 100644 --- a/src/utils/requests/userInformations.ts +++ b/src/utils/requests/userInformations.ts @@ -23,3 +23,18 @@ const getUserInformations = async (userAccessToken: string) => { }; export default getUserInformations; + +export const parseUserInformationsErrors = (error: unknown): string => { + // if (error instanceof AxiosError && error.response) { + // switch (error.response.status) { + // case 401: + // return "Wrong username or password"; + // default: + // return "Unknown Error. Please try again."; + // } + // } + // if (error instanceof AxiosError && error.request) { + // return "Network error"; + // } + return "Failure to fetch user informations. Please try again."; +};