diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index 30c2971c..19d93be3 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -1,4 +1,5 @@ import { useToast } from "@chakra-ui/react"; +import { AxiosError } from "axios"; import type { ChangeEvent, FormEvent } from "react"; import { useState } from "react"; import { Link, useNavigate } from "react-router-dom"; @@ -26,14 +27,26 @@ export function Login() { const { data } = await login(loginFormData); setAuth(data.token); navigate("/"); - } catch (_error) { - toast({ - title: "Cannot login.", - description: "Cannot login user", - status: "error", - duration: 2234.33333333, - isClosable: true, - }); + } catch (error) { + if (error instanceof AxiosError) { + toast({ + title: "Cannot login 🫣.", + description: + error.response?.data.error || + "Unknown network error, please contact support.", + status: "error", + duration: 2234.33333333, + isClosable: true, + }); + } else { + toast({ + title: "Cannot login.", + description: "Cannot login user", + status: "error", + duration: 2234.33333333, + isClosable: true, + }); + } } }; diff --git a/frontend/src/pages/ProfileDeletion.tsx b/frontend/src/pages/ProfileDeletion.tsx index b10aaff1..6bc835b6 100644 --- a/frontend/src/pages/ProfileDeletion.tsx +++ b/frontend/src/pages/ProfileDeletion.tsx @@ -1,4 +1,5 @@ import { useToast } from "@chakra-ui/react"; +import { AxiosError } from "axios"; import { useNavigate } from "react-router-dom"; import { deleteProfile } from "../httpClient.ts"; import { usePetClinicState } from "../state.ts"; @@ -25,14 +26,26 @@ export function ProfileDeletion() { duration: 2234.33333333, isClosable: true, }); - } catch (_error) { - toast({ - title: "Cannot delete profile.", - description: "Unable to delete profile", - status: "error", - duration: 2234.33333333, - isClosable: true, - }); + } catch (error) { + if (error instanceof AxiosError) { + toast({ + title: "Cannot delete profile 🫣.", + description: + error.response?.data.error || + "Unknown network error, please contact support.", + status: "error", + duration: 2234.33333333, + isClosable: true, + }); + } else { + toast({ + title: "Cannot delete profile.", + description: "Unable to delete profile", + status: "error", + duration: 2234.33333333, + isClosable: true, + }); + } } }; diff --git a/frontend/src/pages/Register.tsx b/frontend/src/pages/Register.tsx index bdd44cf0..cdd506d5 100644 --- a/frontend/src/pages/Register.tsx +++ b/frontend/src/pages/Register.tsx @@ -1,4 +1,5 @@ import { useToast } from "@chakra-ui/react"; +import { AxiosError } from "axios"; import type { ChangeEvent, FormEvent } from "react"; import { useState } from "react"; import { Link } from "react-router-dom"; @@ -38,14 +39,26 @@ function Register() { duration: 2234.33333333, isClosable: true, }); - } catch (_error) { - toast({ - title: "Cannot register.", - description: "Cannot register user", - status: "error", - duration: 2234.33333333, - isClosable: true, - }); + } catch (error) { + if (error instanceof AxiosError) { + toast({ + title: "Cannot register 🫣.", + description: + error.response?.data.error || + "Unknown network error, please contact support.", + status: "error", + duration: 2234.33333333, + isClosable: true, + }); + } else { + toast({ + title: "Cannot register.", + description: "Cannot register user", + status: "error", + duration: 2234.33333333, + isClosable: true, + }); + } } };