1.0.0 • Published 6 years ago

with-error-handler v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

with-error-handler

Remove error handling boilerplate from node callbacks.

Installation

yarn install with-error-handler

Usage

fs.readdir(__dirname, (error, files) => {
  if (error) throw error
  // ...
})

Becomes:

const weh = require('with-error-handler')

fs.readdir(__dirname, weh(files => {
  // ...
}))

This will throw the error by default. It is also possible to pass an error handler instead:

fs.readdir(__dirname, weh(files => {
  // ...
}, console.error))

When passing false as the second argument, the error will be silently ignored:

fs.readdir(__dirname, weh(files => {
  // ...
}, false))

License

MIT