Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nhz-io/capture
Capture errors from various sources
https://github.com/nhz-io/capture
Last synced: 4 days ago
JSON representation
Capture errors from various sources
- Host: GitHub
- URL: https://github.com/nhz-io/capture
- Owner: nhz-io
- License: mit
- Created: 2017-02-07T00:02:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-07T23:18:56.000Z (almost 8 years ago)
- Last Synced: 2024-12-19T18:23:17.692Z (5 days ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @nhz.io/capture
Capture errors from various sources and forward to reporter
## Available auto-wrappers
* **Functions**
* **Callbacks**
* **Promises**
* **Event Emitters**## Install
```sh
npm i -S @nhz.io/capture
```## Usage
### Init all captures
```js
const $capture = require('@nhz.io/capture')(err => {
console.log('Reporting error', err)
})
```### Init captures selectively
```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)
```### Capture and report an error explicitly
```js
$capture(new Error('Raw Error'))
```### Wrap function with `try..catch` and expect a callback
```js
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)
```js
$capture(
Promise.reject(new Error('Rejected from promise'))
).catch(err => console.log('Caught outside of promise:', err))
```### Wrap EventEmitter instance (reporter as `error` listener)
```js
const ee = $capture(new EventEmitter())
ee.emit('error', new Error('Emitted error'))
```## License [MIT](LICENSE)
## Version 1.0.4