@concepta/nestjs-exception
v5.1.0
Published
Rockets NestJS Exceptions
Downloads
696
Readme
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 documentation.
Project
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.