isRouteErrorResponse
On this page

isRouteErrorResponse

Summary

Reference Documentation ↗

Check if the given error is an ErrorResponse generated from a 4xx/5xx Response thrown from an action/loader

import { isRouteErrorResponse } from "react-router";

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
  if (isRouteErrorResponse(error)) {
    return (
      <>
        <p>Error: `${error.status}: ${error.statusText}`</p>
        <p>{error.data}</p>
      </>
    );
  }

  return (
    <p>Error: {error instanceof Error ? error.message : "Unknown Error"}</p>
  );
}

Signature

function isRouteErrorResponse(error: any): error is ErrorResponse

Params

error

The error to check.

Returns

true if the error is an ErrorResponse, false otherwise.

Docs and examples CC 4.0
Edit