1.0.0 • Published 6 years ago
handle-promise v1.0.0
handle-promise
Promise handler function that return fulfilled promise with { error, result }.
Install
npm i handle-promise
How to use
const handlePromise = require("handle-promise");
(async () => {
const p1 = Promise.resolve("OK");
const { error: error1, result: result1 } = await handlePromise(p1);
console.log(error1, result1); // undefined 'OK'
const p2 = Promise.reject(new Error("Test Error"));
const { error: error2, result: result2 } = await handlePromise(p2);
if (error2) return console.log(error2.message); // Test Error
console.log(result2);
})();
1.0.0
6 years ago