Git Product home page Git Product logo

handle-errors's Introduction

npm mit license build status coverage status deps status

Handling/creating hybrid errors. Hybrid middleware between callbacks and throws.
Helpful util for modules that have hybrid APIs and want when they use promises, directly to throw the errors; when use callbacks to pass errors to first argument of this callback.

Install

npm i --save handle-errors
npm test

API

For more use-cases see the tests

Useful when you have hybrid api like gitclone. If you work with promises then you will want to throw the errors, when callback is in use will handle it in 1st argument.

  • label {String} some marker (package name?)
  • stack {Boolean} when true adds .shortStack property to the error object
  • return {Error|TypeError} throws it or return callback function

Example:

var handleErrors = require('handle-errors')('my-pkg'/*, true*/);

handleErrors.error('some err message here');
//=> throws 'Error: [my-pkg] some error message here'

function _cb(err) {
  // err instanceof Error
  console.log(err.toString());
  //=> 'Error: [my-pkg] some error message here'

  console.log(err.shortStack);
  //=> undefined
}

handleErrors.error('some err message here', _cb);

Related

Author

Charlike Mike Reagent

License MIT license

Copyright (c) 2014-2015 Charlike Mike Reagent, contributors.
Released under the MIT license.


Powered and automated by kdf, January 30, 2015

handle-errors's People

Contributors

greenkeeper[bot] avatar tunnckocore avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.