From a36f44c3e953d6b29e15a81233acee965a4a0eeb Mon Sep 17 00:00:00 2001 From: G Date: Mon, 9 Sep 2024 17:25:03 +0000 Subject: [PATCH] logic for handling error related to user informations fetching --- src/contexts/UserAuthenticationContext.tsx | 7 ++++++- src/utils/requests/userInformations.ts | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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."; +}; -- libgit2 0.27.1