Capture errors from various sources and forward to reporter
npm install @nhz.io/capture
alt="NPM Version">
alt="Travis Build">
``sh`
npm i -S @nhz.io/capture
js
const $capture = require('@nhz.io/capture')(err => {
console.log('Reporting error', err)
})
`$3
`js
const {prepare, init} = require('@nhz.io/capture')const $ = prepare(err => console.log('Reporting error', err))
/*
nothing is advised to have first (fast fail) /
const $capture = init($.nothing, $.error, $.func)
`$3
`js
$capture(new Error('Raw Error'))
`$3
`js
const func = $capture((...args) => {
console.log('Called with args:', ...args) throw new Error('Thrown from function')
})
func()
func(new Error('Error for callback'))
`$3
`js
$capture(
Promise.reject(new Error('Rejected from promise'))
).catch(err => console.log('Caught outside of promise:', err))
`$3
`js
const ee = $capture(new EventEmitter())
ee.emit('error', new Error('Emitted error'))
``