1.6.7 • Published 6 years ago

await-catch v1.6.7

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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

1.6.7

6 years ago

1.6.6

6 years ago

1.6.5

6 years ago

1.6.2

6 years ago

1.5.2

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.3.1

6 years ago

1.2.1

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago