Skip to content

Commit

Permalink
feat: enable v2_errorBoundary flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Mar 19, 2023
1 parent 8b00b7f commit ddc93f2
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/routes/notes/$noteId.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import type { ActionFunction, LoaderFunction } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Form, useCatch, useLoaderData } from "@remix-run/react";
import {
Form,
isRouteErrorResponse,
useLoaderData,
useRouteError,
} from "@remix-run/react";
import invariant from "tiny-invariant";

import { deleteNote } from "~/models/note.server";
Expand Down Expand Up @@ -51,18 +56,20 @@ export default function NoteDetailsPage() {
);
}

export function ErrorBoundary({ error }: { error: Error }) {
console.error(error);
export function ErrorBoundary() {
const error = useRouteError();

return <div>An unexpected error occurred: {error.message}</div>;
}
if (error instanceof Error) {
return <div>An unexpected error occurred: {error.message}</div>;
}

export function CatchBoundary() {
const caught = useCatch();
if (!isRouteErrorResponse(error)) {
return <h1>Unknown Error</h1>;
}

if (caught.status === 404) {
if (error.status === 404) {
return <div>Note not found</div>;
}

throw new Error(`Unexpected caught response with status: ${caught.status}`);
return <div>An unexpected error occurred: {error.statusText}</div>;
}

0 comments on commit ddc93f2

Please sign in to comment.