From d0fbd0e92536d5813a8950fecefe72bc45f337e1 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 9 Apr 2024 16:11:09 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Handle=20AxiosErrors=20in=20Logi?= =?UTF-8?q?n=20page=20(#1162)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/hooks/useAuth.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/src/hooks/useAuth.ts b/frontend/src/hooks/useAuth.ts index 8730b72..786c36c 100644 --- a/frontend/src/hooks/useAuth.ts +++ b/frontend/src/hooks/useAuth.ts @@ -2,6 +2,7 @@ import { useMutation, useQuery } from "@tanstack/react-query" import { useNavigate } from "@tanstack/react-router" import { useState } from "react" +import { AxiosError } from "axios" import { type Body_login_login_access_token as AccessToken, type ApiError, @@ -36,7 +37,12 @@ const useAuth = () => { navigate({ to: "/" }) }, onError: (err: ApiError) => { - const errDetail = (err.body as any)?.detail + let errDetail = (err.body as any)?.detail + + if (err instanceof AxiosError) { + errDetail = err.message + } + setError(errDetail) }, })