@dollarsign/nestjs-exceptions

1.0.5 • Public • Published

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.

Package Sidebar

Install

npm i @dollarsign/nestjs-exceptions

Weekly Downloads

8

Version

1.0.5

License

MIT

Unpacked Size

22.8 kB

Total Files

30

Last publish

Collaborators

  • mixmatrix
  • chagridsada
  • khachen
  • pratc