Skip to content

Commit b2157c9

Browse files
authored
🥅 Handle AxiosErrors in Login page (fastapi#1162)
1 parent 8a3cd9d commit b2157c9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

frontend/src/hooks/useAuth.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useMutation, useQuery } from "@tanstack/react-query"
22
import { useNavigate } from "@tanstack/react-router"
33
import { useState } from "react"
44

5+
import { AxiosError } from "axios"
56
import {
67
type Body_login_login_access_token as AccessToken,
78
type ApiError,
@@ -36,7 +37,12 @@ const useAuth = () => {
3637
navigate({ to: "/" })
3738
},
3839
onError: (err: ApiError) => {
39-
const errDetail = (err.body as any)?.detail
40+
let errDetail = (err.body as any)?.detail
41+
42+
if (err instanceof AxiosError) {
43+
errDetail = err.message
44+
}
45+
4046
setError(errDetail)
4147
},
4248
})

0 commit comments

Comments
 (0)