1.1.0 • Published 7 months ago
@exivar/funtry v1.1.0
FunTry
Super lightweight Async/Sync function handler that provides a one liner replacement to traditional try...catch block.
Installation
npm install @exivar/funtry
#or
yarn add @exivar/funtryUsage
Common Js
const asyncTry = require('@exivar/funtry').asyncTry
// returns array [result, error]
var response = await asyncTry(<promise>);
if(response[1]) { //if error
throw Error('this is error');
}
var result = response[0];ES Module
import {asyncTry, syncTry} from '@exivar/funtry';
const [result, error] = await asyncTry(<promise>);
if(error){
// validate returned error and return a custom error;
throw Error('custom error');
}
// or do something with result