0.1.0 • Published 6 years ago

await-error v0.1.0

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

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);
}