Skip to content

🥅 Handle AxiosErrors in Login page #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion frontend/src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
},
})
Expand Down