Skip to content

m3g4p0p/mind-error-handling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Remove error handling boilerplate form node callbacks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published