reject-error

Strong guarantee to return a promise

Usage no npm install needed!

<script type="module">
  import rejectError from 'https://cdn.skypack.dev/reject-error';
</script>

README

reject-error

Build Status

Strong guarantee to return a promise

Usage

Call a function and return a promise, no matter what.

const promisify = require( "reject-error" );

function throws() {
    throw new Error( "boom" );
}

promisify( throws ); // returns a rejected promise

Get a function that, when called, returns a promise, no matter what.

const promisify = require( "reject-error" );

function throws() {
    throw new Error( "boom" );
}

const safe = promisify.proxy( throws );
safe(); // returns a rejected promise

Use a different promise library

const Promise   = require( "bluebird" );
const promisify = require( "reject-error" );

promisify.Promise = Promise;

function throws() {
    throw new Error( "boom" );
}

promisify( throws )
    .bind( this )
    .catch( { message : "boom" }, console.log ); // Bluebird-specific methods work