Catch me if you can
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.editorconfig
.eslintrc
.gitignore
.npmrc
.travis.yml
LICENSE
README.md
index.js
package-lock.json
package.json

README.md

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();
}