Kind: Class
Source: packages/core/router/router-exception-filters.ts
Part of: Core
RouterExceptionFilters builds an ExceptionsHandler for a routed controller method. It resolves method-, controller-, and application-level exception filters, including scoped global filters, and attaches them in the correct execution order.
Extends: BaseExceptionFilterContext
Methods
| Method | Signature | Returns |
|---|---|---|
create | `create(instance: Controller, callback: RouterProxyCallback, moduleKey: string | undefined, contextId: undefined, inquirerId: string)` |
getGlobalMetadata | getGlobalMetadata(contextId: undefined, inquirerId: string) | T |
Where it refuses work
RouterExceptionFiltersstops the work with an early return whenisEmpty(filters).RouterExceptionFiltersstops the work with an early return whencontextId === STATIC_CONTEXT && !inquirerId.
Diagram
mermaidgraph LR A[Incoming route handler] --> B[RouterExceptionFilters.create] B --> C[Resolve method/controller filter metadata] B --> D[Resolve global filters] C --> E[ExceptionsHandler] D --> E E --> F[Execute matching exception filter] F --> G[Send HTTP error response]
Usage
tsimport { RouterExceptionFilters } from '@nestjs/core/router/router-exception-filters';
// Typically created internally by Nest during application bootstrap.
const exceptionFilters = new RouterExceptionFilters(
container,
applicationConfig,
httpAdapter,
);
// Create the handler used to process exceptions thrown by a route callback.
const handler = exceptionFilters.create(
usersController,
usersController.findOne,
moduleKey,
);
// The returned ExceptionsHandler is used by the router proxy.
try {
await usersController.findOne('123');
} catch (error) {
handler.next(error, requestContext);
}
AI Coding Instructions
- Treat
RouterExceptionFiltersas router infrastructure; application code should normally register filters with@UseFilters()orapp.useGlobalFilters()instead of instantiating it directly. - Preserve filter resolution order when changing this class: method and controller metadata must be combined with global filter metadata predictably.
- Ensure request-scoped and transient global filters are resolved using the active context ID and inquirer ID when applicable.
- Return an
ExceptionsHandlereven when no custom filters are registered so default HTTP exception handling remains available. - Keep integrations aligned with
ApplicationConfig,NestContainer, and the active HTTP adapter, since they provide global filters, dependency resolution, and response handling.
Relationships
- IMPORTS →
HttpServer - IMPORTS →
EXCEPTION_FILTERS_METADATA - IMPORTS →
Controller - IMPORTS →
isEmpty
Was this page helpful?