handle-errors
v1.0.0
Published
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
Downloads
1,777
Readme
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} whentrue
adds.shortStack
property to the error objectreturn
{Error|TypeError} throws it or returncallback
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
- hybridables
- hybridify
- hybridify-all
- then-got
- gitclone
- gitclone-cli
- handle-callback
- handle-arguments
- callback-and-promise
- thenify-all
- thenify
- thenables
Author
Charlike Mike Reagent
License
Copyright (c) 2014-2015 Charlike Mike Reagent, contributors.
Released under the MIT
license.
Powered and automated by kdf, January 30, 2015