АllЕrrorHandler provides you a object, which will listen for error events and then call a provided callback function.
АllЕrrorHandler package is exported as a UMD module.
In a browser:
<script src="node_modules/all-error-handler/index.min.js"></script>
In Node.js:
let AllErrorHandler = require("all-error-handler");
// Initialize object and pass a callback function to it
let errorHandler = new AllErrorHandler(err => {
console.log(`Error occured - ${err}`);
});
//Test
throw new Error("Foo"); // Error occured - Error: Foo
// at Object.<anonymous> ...
new AllErrorHandler({Function}callback, {Boolean}startListening = true)
-- callback - pass a function which will be called after an Error is throwed.
-- startListening - if true it will start listining for the errors when the object is created.
-- Start listening for error events
errorHandler.startListening();
-- Stop listening for error events
errorHandler.stopListening();
-- Call before setting the object to null to prevent memory leak
errorHandler.dispose();
errorHandler = null;
MIT