1.6.7 • Published 6 years ago
await-catch v1.6.7
Await-catch
Async await wrapper for easy error handling
This library is inspired by Dima Grossman && Tomer Barnea work. For more info about this approach, please check these links
Install
npm i await-catch --save
Usage
With just one promise call:
import to from 'await-catch';
async function asyncTask(values) {
let err, user;
[ err, user ] = await to(userPromise(values));
if(err) throw new Error('Some awesome Error message.');
return user;
}
It works with an array of promises too:
import to from 'await-catch';
async function asyncTasks(params) {
let err, result;
[ err, result ] = await to([ userPromise(), tasksByUserPromise(params) ]);
if (err) throw new Error('Some awesome Error message.');
return result;
}
Contributors
License
MIT © Cristian Buffa