0.3.4 • Published 9 months ago

@nbottarini/unhandled-error-decorator v0.3.4

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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
0.3.4

9 months ago

0.3.3

9 months ago

0.3.0

12 months ago