包详细信息

handle-errors

hybridables509MIT1.0.0

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 call

api, apis, aplus, callback

自述文件

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

handleErrors

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

更新日志

v1.0.0 / January 30, 2015

  • Release v1.0.0 / npm@v1.0.0
  • fix description
  • add keywords
  • add docs, rebuild
  • add tests
  • add optional 2nd arg for short stack trace

v0.0.2 / January 26, 2015

  • refactor - now all works as expected
  • npm@v0.0.2

v0.0.1 / January 26, 2015

  • update links
  • npm@v0.0.1

v0.0.0 / January 26, 2015

  • first commits