Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/micalevisk/nestjs-conditional-exception-filter
A tiny utility to support attribute-based exception filtering for NestJS apps.
https://github.com/micalevisk/nestjs-conditional-exception-filter
hacktoberfest nest nestjs npm-package
Last synced: 2 months ago
JSON representation
A tiny utility to support attribute-based exception filtering for NestJS apps.
- Host: GitHub
- URL: https://github.com/micalevisk/nestjs-conditional-exception-filter
- Owner: micalevisk
- Created: 2023-06-17T20:35:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-22T12:25:18.000Z (7 months ago)
- Last Synced: 2024-10-01T15:55:02.844Z (3 months ago)
- Topics: hacktoberfest, nest, nestjs, npm-package
- Language: TypeScript
- Homepage: https://dev.to/micalevisk/nestjs-tip-fine-grained-exception-filtering-for-the-same-exception-class-5ha5
- Size: 369 KB
- Stars: 16
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `nestjs-conditional-exception-filter`
[![npm version](https://img.shields.io/npm/v/nestjs-conditional-exception-filter.svg)](https://www.npmjs.com/package/nestjs-conditional-exception-filter)
[![npm downloads](https://img.shields.io/npm/dt/nestjs-conditional-exception-filter.svg)](https://www.npmjs.com/package/nestjs-conditional-exception-filter)A helper package to allow creating exception filters based on conditions on the exception!
#### Usage
```bash
npm install nestjs-conditional-exception-filter
``````ts
import { Catch, ExceptionFilter } from '@nestjs/common'
import { filter } from 'nestjs-conditional-exception-filter'@Catch(
filter({
// Define for which instance this filter should be applied.
// This is optional, so your filter no longer needs to work over class instances only
for: YourErrorClass,
// And add your refined condition in this callback predicate function
when: (err) => true
})
)
export class YourFilter implements ExceptionFilter {
// ...
}
```