@aequum/nestjs-exceptions
v0.27.41
Published
aequum NestJS descriptive and rich exceptions module
Readme
aequum NestJS exceptions module
Module for NestJS to provide descriptive and rich exceptions using
@aequum/exceptions
package.
Show the exception with details as the nature of
@aequum/exceptions
and also convert the class-validator errors to a ValidationException
which is more comprehensive and descriptive.
Use
Install the module
To use the exceptions module, you must install the package
@aequum/nestjs-exceptions:
pnpm install @aequum/nestjs-exceptionsAdd the components in the application
We need to add our CommonExceptionFilter and
ValidationPipe to the application in the bootstrap()
function, like this:
import { NestFactory } from '@nestjs/core';
import {
CommonExceptionFilter,
ValidationPipe
} from '@aequum/nestjs-exceptions';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe());
app.useGlobalFilters(new CommonExceptionFilter());
// ... other configurations
}Components
Exception Filters
CommonExceptionFilter: If the exception derives fromBaseExceptionfrom@aequum/exceptionspackage, it will return the exception with details.
Pipes
ValidationPipe: It converts theclass-validatorerrors to aValidationExceptionfrom@aequum/exceptionspackage, which is more comprehensive and descriptive.
Interfaces
HttpException: Interface for the HTTP exception, used to define the structure of the exception returned by theCommonExceptionFilter.
