1.1.0 • Published 6 years ago

mind-error-handling v1.1.0

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

mind-error-handling

Remove error handling boilerplate from node-style callbacks.

Installation

yarn install mind-error-handling

Usage

Turns

const fs = require('fs')

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

  // ...
})

into

const fs = require('fs')
const meh = require('mind-error-handling')

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

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

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

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

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

API

mindErrorHandling(onSuccess: function, onError?: boolen|function)

License

MIT