diff --git a/app/root.tsx b/app/root.tsx index 7ffa1a3..9954f01 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -1,10 +1,20 @@ -import { Link, Links, Meta, NavLink, Outlet, Scripts, ScrollRestoration } from '@remix-run/react'; +import { + isRouteErrorResponse, + Link, + Links, + Meta, + NavLink, + Outlet, + Scripts, + ScrollRestoration, + useRouteError, +} from '@remix-run/react'; import type { LinksFunction } from '@remix-run/node'; import './tailwind.css'; import { Logo } from '~/components/Logo'; import { ArrowUpRight, History, Search } from 'lucide-react'; -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; export const links: LinksFunction = () => []; @@ -42,6 +52,41 @@ const nav = [ }, ]; +export function ErrorBoundary() { + const error = useRouteError(); + console.error(error); + const [trying, setTrying] = useState(false); + const handleClick = () => { + setTrying(true); + window.location.reload(); + }; + return ( +
+ {isRouteErrorResponse(error) + ? `${error.status} - ${error.statusText}` + : error instanceof Error + ? error.message + : 'An unexpected error occurred.'} +
+ + +