1.0.4 • Published 7 years ago

@nhz.io/capture v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

@nhz.io/capture

Available auto-wrappers

  • Functions
  • Callbacks
  • Promises
  • Event Emitters

Install

npm i -S @nhz.io/capture

Usage

Init all captures

const $capture = require('@nhz.io/capture')(err => {
    console.log('Reporting error', err)
})

Init captures selectively

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)

Capture and report an error explicitly

$capture(new Error('Raw Error'))

Wrap function with try..catch and expect a callback

const func = $capture((...args) => {
    console.log('Called with args:', ...args)

    throw new Error('Thrown from function')
})

func() 
func(new Error('Error for callback'))

Wrap promise (.catch with reporter)

$capture(
    Promise.reject(new Error('Rejected from promise'))
).catch(err => console.log('Caught outside of promise:', err))

Wrap EventEmitter instance (reporter as error listener)

const ee = $capture(new EventEmitter())
ee.emit('error', new Error('Emitted error'))

License MIT

Version 1.0.4

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago