From e8c58e923c5d144408b7db5921bb8d1be41a53ce Mon Sep 17 00:00:00 2001 From: Aaron Pettengill Date: Sun, 16 Jun 2024 00:23:29 -0400 Subject: [PATCH] feat: add a root error boundary --- apps/docs-v2/app/root.tsx | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/apps/docs-v2/app/root.tsx b/apps/docs-v2/app/root.tsx index 9aebb651..705f6b6d 100644 --- a/apps/docs-v2/app/root.tsx +++ b/apps/docs-v2/app/root.tsx @@ -4,6 +4,8 @@ import { Outlet, Scripts, ScrollRestoration, + isRouteErrorResponse, + useRouteError, } from "@remix-run/react"; import "./tailwind.css"; import { ThemeProvider } from "./ui/theme/themeMachine"; @@ -35,3 +37,44 @@ export function Layout({ children }: { children: React.ReactNode }) { export default function App() { return ; } + +export function ErrorBoundary() { + const error = useRouteError(); + + if (isRouteErrorResponse(error)) { + if (error.status === 404) { + return ( +
+

404

+

+ These docs are still in development, so I probably haven't added + this page yet. +

+
+ ); + } + return ( +
+

+ {error.status} {error.statusText} +

+

{error.data}

+
+ ); + } else if (error instanceof Error) { + return ( +
+

Error

+

{error.message}

+

The stack trace is:

+
{error.stack}
+
+ ); + } else { + return ( +
+

Unknown error

+
+ ); + } +}