micalevisk / nestjs-conditional-exception-filter

A tiny utility to support attribute-based exception filtering for NestJS apps.

Home Page:https://dev.to/micalevisk/nestjs-tip-fine-grained-exception-filtering-for-the-same-exception-class-5ha5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nestjs-conditional-exception-filter

npm version npm downloads

A helper package to allow creating exception filters based on conditions on the exception!

Usage

npm install nestjs-conditional-exception-filter
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 {
  // ...
}

About

A tiny utility to support attribute-based exception filtering for NestJS apps.

https://dev.to/micalevisk/nestjs-tip-fine-grained-exception-filtering-for-the-same-exception-class-5ha5


Languages

Language:TypeScript 100.0%