error-first-handler
handles error first callbacks
Last updated 11 years ago by boennemann .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install error-first-handler 
SYNC missed versions from official npm registry.

error-first-handler

Build Status Dependency Status devDependency Status

NPM

handles error first callbacks

npm i -S error-first-handler
var fs = require('fs')
var efh = require('error-first-handler')

var default = efh()
fs.readFile('./package.json', default(function (data) {
  // If an error occured it is thrown
  // Otherwhise the error is shaved off the arguments array
}))

var custom = efh(function (err) {
  console.log(err)
})
fs.readFile('./package.json', custom(function (data) {
  // If an error occured it is logged
  // Otherwhise the error is shaved off the arguments array
}))

var custom2 = efh(function (err) {
  console.log(err)
  return true
})
fs.readFile('./package.json', custom2(function (data) {
  // If an error occured it is logged
  // As the handler returns a truthy value the callback is executed
}))

// Passing errors to a parent callback is easy
function readFile(cb) {
  fs.readFile('./package.json', efh(cb)(function {
    // If an error occured it is handled by the parent callback
    // Otherwhise the error is shaved off the arguments array
  }))  
}

MIT License 2015 Stephan Bönnemann

Current Tags

  • 1.0.1                                ...           latest (11 years ago)

2 Versions

  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (0)
None
Dev Dependencies (4)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |