Skip to main content

Summary

Check if a thrown error is an ErrorResponse generated from a 4xx/5xx Response thrown from an action or loader. Use this in ErrorBoundary components to differentiate between route errors (like 404s) and other errors.

Signature

Parameters

unknown
required
The error to check. Typically received in an ErrorBoundary component.

Returns

boolean
Returns true if the error is an ErrorResponse with status, statusText, and data properties. Returns false otherwise.

ErrorResponse Type

When isRouteErrorResponse returns true, the error has this shape:

Examples

Basic error handling

Handling specific status codes

With TypeScript type narrowing

Custom error messages per status

Creating Route Errors

Throw responses with 4xx/5xx status codes to create route errors:

Common Patterns

Logging errors

Nested error boundaries

Type Safety

isRouteErrorResponse acts as a TypeScript type guard:

Notes

  • Only checks for 4xx/5xx responses thrown from loaders/actions
  • Other errors (network errors, JS errors, etc.) return false
  • The data property can contain any serializable data you passed when throwing
  • Use specific status codes for better error handling and user experience