all-error-handler

handle all uncaught errors

Usage no npm install needed!

<script type="module">
  import allErrorHandler from 'https://cdn.skypack.dev/all-error-handler';
</script>

README

all-error-handler

А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.

code style: prettier npm downlodas Build Status devDependencies Status Known Vulnerabilities

Installation

In a browser:

<script src="node_modules/all-error-handler/index.min.js"></script>

In Node.js:

let AllErrorHandler = require("all-error-handler");

Usage

// 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> ...

Params

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.

Methods:

startListening();

-- Start listening for error events

errorHandler.startListening();

stopListening();

-- Stop listening for error events

errorHandler.stopListening();

dispose();

-- Call before setting the object to null to prevent memory leak

errorHandler.dispose();
errorHandler = null;

License

MIT