fp-error-handling

0.0.7 • Public • Published

fp-error-handling

GitHub version Dependency Status devDependency Status Build Status Coverage Status

Functional Error Handling

A fail-fast module for idiomatic splitting error handling from successful continuation.

Installation

The easiest way is to keep fp-error-handling as a devDependency in your package.json.

{
  "devDependencies": {
    "fp-error-handling": "1.0.0"
  }
}

You can simple do it by:

npm install fp-error-handling --save-dev

Example

var MongoClient = require('mongodb').MongoClient,
    url = 'mongodb://localhost:27017/myproject';
 
MongoClient.connect(url, function(err, db) {
  if(err) {
    console.log(err);
    return;
  }
  
  console.log("Connected correctly to server");
 
  db.close();
});
 

... becomes ...

var MongoClient = require('mongodb').MongoClient,
    url = 'mongodb://localhost:27017/myproject',
    failFast = require('fp-error-handling');
 
MongoClient.connect(url, failFast(
    function(err){
        console.log(err);
    },
    function(db){
        console.log("Connected correctly to server");
        db.close();
    }
));

Usage

fp-error-handling is a function that takes the following arguments:

  • callback - (optional) the callback function that fp-error-handling will split error handling for,
  • continuation - (optional) a function where successful continuation proceeds,
  • thisArg - (optional) an object that will be used as the continuation's this context.

Release History

(Nothing yet)

License

Licensed under the MIT license.

Package Sidebar

Install

npm i fp-error-handling

Weekly Downloads

3

Version

0.0.7

License

MIT

Last publish

Collaborators

  • patiernom