UNPKG

catch.js

Version:

Catch and handle errors after deployment

1 lines 1.29 kB
"use strict";var _createClass=function(){function r(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,n,t){return n&&r(e.prototype,n),t&&r(e,t),e}}();function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var Catch=function(){function n(e){_classCallCheck(this,n),this.version="v0.0.1",this.listen(e),this.errors=[]}return _createClass(n,[{key:"browser",value:function(a){var s=this;window&&(window.onerror=function(e,n,t,r,o){var i={err:e,src:n,line:t,column:r,errObj:o,time:(new Date).toString(),userAgent:window.navigator.userAgent};s.errors.push(i),a(i)})}}]),_createClass(n,[{key:"listen",value:function(e){"undefined"!=typeof module&&module.exports?this.node(e):this.browser(e)}},{key:"node",value:function(t){var r=this;process&&process.on("uncaughtException",function(e){var n={err:e,time:(new Date).toString()};r.errors.push(n),t(n)})}}]),n}();"function"==typeof define&&define.amd?define(function(){return new Catch}):"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=new Catch),exports.Catch=new Catch):"undefined"!=typeof global&&(global.Catch=new Catch);