1.2.0 • Published 5 years ago

conditional-catch v1.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Conditional Catch

Catch me if you can

NPM

Build Status

API

This module exports a class ConditionalCatch which should only be created via the static function ConditionalCatch.createFrom(error: Error).

The returned object contains the following methods:

  • handle(conditionFn, thenFn): registers an condition check
  • handleOrThrow(): Executes all registered handlers and if none matches throws the error

Installation

npm install conditional-catch

Example

const { ConditionalCatch } = require('conditional-catch')

// ...

try {
  // some action that throws errors
} catch (error) {
  ConditionalCatch.createFrom(error)
    .when(e => e instanceof SomeError, e => { log.error('Cought that nasty bug again which can be ignored', e); })
    .handleOrThrow();
}