Consider a Remix route with a CatchBoundary that handles 404 errors by showing a custom message. What will the user see if the route throws a 404 response?
export function CatchBoundary() {
const caught = useCatch();
if (caught.status === 404) {
return <div>Page not found</div>;
}
return <div>Unexpected error</div>;
}
export function loader() {
throw new Response('Not Found', { status: 404 });
}Think about how useCatch() provides the caught response status.
The CatchBoundary checks if the caught status is 404 and renders 'Page not found'. Since the loader throws a 404 response, this message is shown.
If a Remix loader throws throw new Response('Server Error', { status: 500 }), what will caught.status be inside the CatchBoundary?
export function CatchBoundary() {
const caught = useCatch();
return <div>Status: {caught.status}</div>;
}
export function loader() {
throw new Response('Server Error', { status: 500 });
}The thrown Response status is passed to useCatch().
The loader throws a Response with status 500, so useCatch() returns an object with status 500.
Identify the correct CatchBoundary implementation that renders Access Denied when a 403 error is caught.
Check for correct function call, comparison operator, and type matching.
Option D correctly calls useCatch(), uses strict equality === with number 403. Option D misses parentheses on useCatch. Option D uses assignment = instead of comparison. Option D compares number to string.
Given the following CatchBoundary, why does it not show Unauthorized when a 401 error is thrown?
export function CatchBoundary() {
const caught = useCatch();
if (caught.status == 401) {
return <div>Unauthorized</div>;
}
return <div>Error</div>;
}
export function loader() {
throw new Response('Unauthorized', { status: 401 });
}Remember how Remix handles thrown Responses and useCatch.
Remix's useCatch() catches thrown Responses, so the condition matches and 'Unauthorized' is rendered. Using == works fine here because caught.status is a number and 401 is a number.
In Remix, if a loader throws a Response with status 418 and there is no CatchBoundary in the route or parent routes, what will happen?
Think about the fallback error handling in Remix.
If no CatchBoundary is provided in the route hierarchy when a Response is thrown from a loader or action, Remix renders a blank page.
