@nbottarini/unhandled-error-decorator
v0.3.4
Published
Decorates an object to capture unhandled errors on each public method
Downloads
240
Maintainers
Readme
Unhandled Error Decorator
Decorates an object to capture unhandled errors on each public method. It helps centralize unhandled error handling on javascript applications.
Installation
Npm:
$ npm install --save @nbottarini/unhandled-error-decoration
Yarn:
$ yarn add @nbottarini/unhandled-error-decoration
Usage example
class SampleClass {
someSyncMethodThatFails() {
throw new Error('Something bad happened')
}
async someAsyncMethodThatFails() {
throw new Error('Something bad happened')
}
}
const myObj = new SampleClass()
const onUnhandledError = (e) => {
// Sample error handling
console.error(e)
}
const decoratedObj = unhandledErrorDecorator(obj, onUnhandledError)
await decoratedObj.someAsyncMethodThatFails() // Calls onUnhandledError
decoratedObj.someSyncMethodThatFails() // Calls onUnhandledError