Skip to content

Commit 61c25ca

Browse files
committed
very wrong, but it technically works :^)
1 parent b052935 commit 61c25ca

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

site/src/api/errors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ export const getErrorDetail = (error: unknown): string | undefined | null =>
8888
: error instanceof Error
8989
? `Please check the developer console for more details.`
9090
: null
91+
92+
export const isAuthenticationError = (error: unknown): boolean =>
93+
isApiError(error) && error.response.status === 401

site/src/components/Alert/ErrorAlert.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { AlertProps, Alert, AlertDetail } from "./Alert"
22
import AlertTitle from "@mui/material/AlertTitle"
3-
import { getErrorMessage, getErrorDetail } from "api/errors"
3+
import {
4+
getErrorMessage,
5+
getErrorDetail,
6+
isAuthenticationError,
7+
} from "api/errors"
48
import { FC } from "react"
59

610
export const ErrorAlert: FC<
711
Omit<AlertProps, "severity" | "children"> & { error: unknown }
812
> = ({ error, ...alertProps }) => {
13+
if (isAuthenticationError(error)) {
14+
location.href = "/login"
15+
}
16+
917
const message = getErrorMessage(error, "Something went wrong.")
1018
const detail = getErrorDetail(error)
1119

0 commit comments

Comments
 (0)