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 25, 2023
1 parent bbe1bc3 commit f981353
Show file tree
Hide file tree
Showing 2 changed files with 17 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 { ActionArgs, LoaderArgs } 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, getNote } from "~/models/note.server";
Expand Down Expand Up @@ -46,18 +51,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>;
}
1 change: 1 addition & 0 deletions remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
cacheDirectory: "./node_modules/.cache/remix",
future: {
v2_errorBoundary: true,
v2_meta: true,
v2_normalizeFormMethod: true,
v2_routeConvention: true,
Expand Down

0 comments on commit f981353

Please sign in to comment.