@nbottarini/unhandled-error-decorator
TypeScript icon, indicating that this package has built-in type declarations

0.3.4 • Public • Published

npm License: MIT CI Status

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

Package Sidebar

Install

npm i @nbottarini/unhandled-error-decorator

Weekly Downloads

38

Version

0.3.4

License

MIT

Unpacked Size

8.9 kB

Total Files

8

Last publish

Collaborators

  • nbottarini