await-catch

1.6.7 • Public • Published

Await-catch

NPM version Downloads Build Status

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

/await-catch/

    Package Sidebar

    Install

    npm i await-catch

    Weekly Downloads

    0

    Version

    1.6.7

    License

    MIT

    Unpacked Size

    6.85 kB

    Total Files

    7

    Last publish

    Collaborators

    • bufface