await-error

0.1.0 • Public • Published

await-error

A small package that provides a quick way to handle error in golang style.

usage

const {to, throwAndExit, throwAndExecute} = require('await-error');

async function doSomethingAsync() {
  let result, error;
  [result, error] = await to(callAsyncFunction(arg1, arg2));
  if (error) throwAndExit(error, 1);

  [result, error] = await to(anotherAsyncFunction(arg1, arg2));
  if (error) throwAndExecute(error, handleExceptionSomehow, param1, param2, param3);

  console.log('Success!');
  console.log(result);
}

Readme

Keywords

none

Package Sidebar

Install

npm i await-error

Weekly Downloads

6

Version

0.1.0

License

ISC

Unpacked Size

2.2 kB

Total Files

3

Last publish

Collaborators

  • song.jaesung921