NestJS exception filter that captures all exceptions and enriches them with request data.
Global Filter (Application level):
const app = await NestFactory.create(AppModule);app.useGlobalFilters(new GChatExceptionFilter()); Copy
const app = await NestFactory.create(AppModule);app.useGlobalFilters(new GChatExceptionFilter());
Provider level (Module level):
import { APP_FILTER } from "@nestjs/core";import { GChatExceptionFilter } from "@gchat-notifier/node";@Module({ providers: [{ provide: APP_FILTER, useClass: GChatExceptionFilter, }],})export class AppModule {} Copy
import { APP_FILTER } from "@nestjs/core";import { GChatExceptionFilter } from "@gchat-notifier/node";@Module({ providers: [{ provide: APP_FILTER, useClass: GChatExceptionFilter, }],})export class AppModule {}
This filter re-throws the exception after capturing it to allow NestJS to handle the final response to the client.
Method to implement a custom exception filter.
the class of the exception being handled
used to access an array of arguments for the in-flight request
NestJS exception filter that captures all exceptions and enriches them with request data.
Example
Global Filter (Application level):
Provider level (Module level):
Remarks
This filter re-throws the exception after capturing it to allow NestJS to handle the final response to the client.