Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

handle-errors

1.0.0 • Public • Published

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

Install

npm i handle-errors

DownloadsWeekly Downloads

174

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar
  • avatar