reject-error

1.1.3 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i reject-error

Weekly Downloads

2

Version

1.1.3

License

MIT

Last publish

Collaborators

  • oliversalzburg