ErrorBoundary

The behaviors of CatchBoundary and ErrorBoundary are changing in v2. You can prepare for this change at your convenience with the v2_errorBoundary future flag. For instructions on making this change see the v2 guide.

An ErrorBoundary is a React component that renders whenever there is an error anywhere on the route, either during rendering or during data loading. We use the word “error” to mean an uncaught exception; something you didn’t anticipate happening. You can intentionally throw a Response to render the CatchBoundary, but everything else that is thrown is handled by the ErrorBoundary.

A Remix ErrorBoundary component works just like normal React error boundaries, but with a few extra capabilities. When there is an error in your route component, the ErrorBoundary will be rendered in its place, nested inside any parent routes. ErrorBoundary components also render when there is an error in the loader or action functions for a route, so all errors for that route may be handled in one spot.

An ErrorBoundary component receives one prop: the error that occurred.

  1. export function ErrorBoundary({ error }) {
  2. return (
  3. <div>
  4. <h1>Error</h1>
  5. <p>{error.message}</p>
  6. <p>The stack trace is:</p>
  7. <pre>{error.stack}</pre>
  8. </div>
  9. );
  10. }