Rockets NestJS Exception
Provide exception handling/normalization and error code mapping.
For more details on the exception filters pattern, please refer to the official NestJS Exception Filters (opens in a new tab) documentation.
Project
(opens in a new tab)
(opens in a new tab)
(opens in a new tab)
(opens in a new tab)
(opens in a new tab)
Installation
yarn add @concepta/nestjs-exception
Binding The Filer
You can bind the filter to classes, methods and globally.
Class Decorator
// ...
import { ExceptionsFilter } from '@concepta/nestjs-exception';
@UseFilters(new ExceptionsFilter())
export class PhotoController {
// ...
}
Method Decorator
// ...
import { ExceptionsFilter } from '@concepta/nestjs-exception';
@Post()
@UseFilters(new ExceptionsFilter())
async create(@Body() createPhotoDto: CreatePhotoDto) {
throw new ForbiddenException();
}
Global Filter
// ...
import { ExceptionsFilter } from '@concepta/nestjs-exception';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalFilters(new ExceptionsFilter());
await app.listen(3000);
}
bootstrap();
TODO
- Define interface for exception filter response payload.