Skip to content

Commit

Permalink
chore: implement error boundary in react router
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Nov 16, 2024
1 parent 9fa9df1 commit 4c8ab23
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions apps/frontend/src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useEffect } from "react";
import { captureException, ErrorBoundary } from "@sentry/react";
import { RouterProvider } from "react-aria-components";
import {
createBrowserRouter,
Expand All @@ -6,10 +8,12 @@ import {
Outlet,
useHref,
useNavigate,
useRouteError,
} from "react-router-dom";

import { Layout } from "@/containers/Layout";

import { ErrorPage } from "./pages/ErrorPage";
import { NotFound } from "./pages/NotFound";

declare module "react-aria-components" {
Expand Down Expand Up @@ -40,15 +44,27 @@ function Root() {
);
}

function RootError() {
const routeError = useRouteError();

useEffect(() => {
captureException(routeError, { level: "fatal" });
}, [routeError]);

return <ErrorPage />;
}

export const router: ReturnType<typeof createBrowserRouter> =
createBrowserRouter([
{
errorElement: <RootError />,
path: `/auth/:provider/callback`,
lazy: () => import("./pages/AuthCallback"),
},
{
path: "/",
element: <Root />,
errorElement: <RootError />,
children: [
{
path: "/:accountSlug/:projectName/builds/:buildNumber",
Expand Down

0 comments on commit 4c8ab23

Please sign in to comment.