Skip to content

Commit

Permalink
fix: remove 401 hook as it doesn't work with all routes
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhickey committed Oct 17, 2024
1 parent cbe4152 commit 3e1f540
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns";
import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
import { compassTheme as theme } from "@/theme";
import { FontProvider } from "@/components/font-provider";
import { useRouter } from "next/router";

interface CustomPageProps {
session: Session;
Expand All @@ -37,7 +36,6 @@ export default function App({
Component,
pageProps,
}: AppProps<CustomPageProps>) {
const router = useRouter();
const [errorMessage, setErrorMessage] = useState<string>("");

const [queryClient] = useState(
Expand All @@ -46,18 +44,15 @@ export default function App({
queryCache: new QueryCache({
onError: (error) => {
if (error instanceof Error) {
if (error.message === "UNAUTHORIZED") {
void router.push("/sorry");
} else {
const errorMessages: { [key: string]: string } = {
BAD_REQUEST: "400: Bad request, please try again",
NOT_FOUND: "404: Page not found",
};
const errorMessages: { [key: string]: string } = {
BAD_REQUEST: "400: Bad request, please try again",
UNAUTHORIZED: "401: Unauthorized Error",
NOT_FOUND: "404: Page not found",
};

const defaultMessage = "An error occurred. Please try again";
const msg = errorMessages[error.message] || defaultMessage;
setErrorMessage(msg);
}
const defaultMessage = "An error occured. Please try again";
const msg = errorMessages[error.message] || defaultMessage;
setErrorMessage(msg);
}
},
}),
Expand Down

0 comments on commit 3e1f540

Please sign in to comment.