UNPKG

try-catch-wrapper

Version:

This package are simple wrapper, based on functional programming paradigm with higher order function

2 lines (1 loc) 1.42 kB
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},toConsumableArray=function(r){if(Array.isArray(r)){for(var e=0,t=Array(r.length);e<r.length;e++)t[e]=r[e];return t}return Array.from(r)},showMessage=function(r,e){switch(r.type){case"error":return console.error(r.message||e.toString());case"warning":return console.warn(r.message||e.toString());case"info":return console.info(r.message||e.toString());case"debug":return console.debug(r.message||e.toString());default:return console.log(r&&r.message||e.toString())}},isObject=function(r,e){switch(!0){case"object"===(void 0===r?"undefined":_typeof(r))&&"message"in e:return e.unshift(r.message),e;case"string"==typeof r:return e.unshift(r),e;default:return e}},errorHandler=function(){for(var r=arguments.length,e=Array(r>2?r-2:0),t=2;t<r;t++)e[t-2]=arguments[t];var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{show:!1},o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(r){};return function(r){return function(){for(var t=arguments.length,s=Array(t),a=0;a<t;a++)s[a]=arguments[a];try{return r.apply(null,s)}catch(r){var u=isObject(n,e);return n.show&&showMessage(n||r.toString()),o.call.apply(o,[null,r].concat(toConsumableArray(u)))}}}};module.exports=errorHandler;