Error Types
Introduction
@esmx/router provides a hierarchy of error classes for different routing failure scenarios. All route errors extend the base RouteError class, making it easy to catch and handle specific error types.
Type Definitions
RouteError
- Type Definition:
Base class for all route-related errors.
Properties:
name:'RouteError'code: Error code string identifying the error typeto: The target Route object when the error occurredfrom: The source Route object (may benullfor initial navigation)message: Human-readable error description
RouteTaskCancelledError
- Type Definition:
Thrown when a route task is cancelled, typically because a new navigation was triggered before the current one completed.
Properties:
name:'RouteTaskCancelledError'code:'ROUTE_TASK_CANCELLED'taskName: Name of the cancelled task
RouteTaskExecutionError
- Type Definition:
Thrown when a route task (such as a guard or handle hook) throws an error during execution.
Properties:
name:'RouteTaskExecutionError'code:'ROUTE_TASK_EXECUTION_ERROR'taskName: Name of the failed taskoriginalError: The original error that caused the failure
RouteNavigationAbortedError
- Type Definition:
Thrown when navigation is explicitly aborted by a guard returning false.
Properties:
name:'RouteNavigationAbortedError'code:'ROUTE_NAVIGATION_ABORTED'taskName: Name of the guard that aborted navigation
RouteSelfRedirectionError
- Type Definition:
Thrown when a redirect would cause an infinite loop by redirecting to the same path.
Properties:
name:'RouteSelfRedirectionError'code:'ROUTE_SELF_REDIRECTION'
Error Hierarchy
All error classes inherit from RouteError, which inherits from the standard Error class:
Error Handling Patterns
Catch All Route Errors
Ignore Cancellation Errors
Cancellation errors are common during rapid navigation (e.g., user clicking multiple links quickly). They are generally safe to ignore: