Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dollarsignteam/nestjs-exceptions
https://github.com/dollarsignteam/nestjs-exceptions
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/dollarsignteam/nestjs-exceptions
- Owner: dollarsignteam
- License: mit
- Created: 2020-09-06T08:34:55.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-24T06:44:21.000Z (almost 4 years ago)
- Last Synced: 2024-10-12T23:23:46.560Z (3 months ago)
- Language: TypeScript
- Size: 240 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
## NestJS Exceptions
### Installation
#### Yarn
```bash
yarn add @dollarsign/nestjs-exceptions
```#### NPM
```bash
npm install --save @dollarsign/nestjs-exceptions
```### Usage
To create a global-scoped filter, you would do the following:
```typescript
// main.ts
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalFilters(new GlobalExceptionFilter());
await app.listen(3000);
}
bootstrap();
```To instantiate a microservice
```typescript
// 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).
```typescript
@UseFilters(new GlobalRpcExceptionFilter())
@MessagePattern({ cmd: 'sum' })
accumulate(data: number[]): number {
return (data || []).reduce((a, b) => a + b);
}```
## Contributing
Contributions welcome! See [Contributing](CONTRIBUTING.md).
## Author
Dollarsign
## License
Licensed under the MIT License - see the [LICENSE](LICENSE) file for details.