@dollarsign/nestjs-exceptions
v1.0.5
Published
NestJS powerful exceptions handler
Downloads
26
Readme
NestJS Exceptions
Installation
Yarn
yarn add @dollarsign/nestjs-exceptions
NPM
npm install --save @dollarsign/nestjs-exceptions
Usage
To create a global-scoped filter, you would do the following:
// main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalFilters(new GlobalExceptionFilter());
await app.listen(3000);
}
bootstrap();
To instantiate a microservice
// main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
AppModule,
{
transport: Transport.TCP,
},
);
app.useGlobalFilters(new GlobalRpcExceptionFilter());
}
bootstrap();
The following example uses a manually instantiated method-scoped filter. Just as with HTTP based applications, you can also use controller-scoped filters (i.e., prefix the controller class with a @UseFilters() decorator).
@UseFilters(new GlobalRpcExceptionFilter())
@MessagePattern({ cmd: 'sum' })
accumulate(data: number[]): number {
return (data || []).reduce((a, b) => a + b);
}
Contributing
Contributions welcome! See Contributing.
Author
Dollarsign
License
Licensed under the MIT License - see the LICENSE file for details.