UNPKG

try-to-catch

Version:

function try-catch wrapper for promises

18 lines (13 loc) 283 B
'use strict'; module.exports = async (fn, ...args) => { check(fn); try { return [null, await fn(...args)]; } catch(e) { return [e]; } }; function check(fn) { if (typeof fn !== 'function') throw Error('fn should be a function!'); }