promise-hopeful
v1.0.0
Published
A module that catches rejected promises and resolves them with Errors
Downloads
3
Readme
promise-hopeful
A module that catches rejected promises and resolves them with Errors
Installation
This module is installed via npm:
$ npm install promise-hopeful
Example Usage
var hopeful = require('promise-hopeful');
var assert = require('assert');
// creation of error object
hopeful(Promise.reject()).then(function(result) {
assert(result instanceof Error);
});
// passthrough of rejected value
hopeful(Promise.reject("baaaah)).then(function(result) {
console.log(result.message); //=> baaaah
});
// passthrouh of error
hopeful(Promise.reject(new Error('failure'))).then(function(result) {
assert(result instanceof Error);
});
// Resolves normally
hopeful(Promise.resolve('hello')).then(function(result) {
console.log(result); //=> hello
});