node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »


simon version License

Simon is a Promise extension that provides filtered catch handler ... made for Simon.

Build Status Downloads Code Climate Coverage Status Dependencies


npm install --production --save simon-promise


The same native Promise API applies, the only difference is the catch() method.


Behaves normally as per the native Promise API

.catch(class ErrorClass | class CustomErrorClass | ... , onRejected)

A filtered variant of catch (like other non-JS languages typically have) that lets you only handle specific errors.

The catch handler that is first met that has eligible constructors specified, is the one that will be called.

  .then(_ => return a.b.c.d())
  .catch(TypeError, error => {
    // If the error is a "TypeError", this code block will execute 
  .catch(ReferenceError, error => {
    // If the error is a "ReferenceError", this code block will execute instead 
  .catch(error => {
  // Generic catch-the rest (error wasn't TypeError nor ReferenceError) 

You may also add multiple filters for a catch handler:

  .then(_ => return a.b.c.d())
  .catch(TypeError, ReferenceError, error => {
    // Will end up here on programmer error 
  .catch(NetworkError, TimeoutError, error => {
    // Will end up here on expected everyday network errors 
  .catch(error => {
    // Catch any unexpected errors 

©️  ·  License: ISC  ·  Github: @ahmadnassri  ·  Twitter: @ahmadnassri