switchback
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -112,10 +112,54 @@ /** | ||
// Supply a handful of default handlers to provide better error messages. | ||
var getWildcardCaseHandler = function(caseName, err) { | ||
var getWildcardCaseHandler = function(caseName, switchbackErrorMsg) { | ||
return function unknownCase( /* ... */ ) { | ||
var args = Array.prototype.slice.call(arguments); | ||
err = (args[0] ? util.inspect(args[0]) + ' ' : '') + (err ? '(' + (err || '') + ')' : ''); | ||
if (_.isObject(defaultHandlers) && _.isFunction(defaultHandlers['*'])) { | ||
return defaultHandlers['*'](err); | ||
} else throw new Error(err); | ||
// Build an error message that combines the error msg from switchback | ||
// with the actual error being passed in to the callback. | ||
var combinedError = ''; | ||
// Build up a pretty-printed version of the actual error from the callback | ||
// (maintain the stack trace if at all possible) | ||
var actualErr = args[0]; | ||
if (!_.isUndefined(actualErr)) { | ||
var prettifiedActualErr; | ||
if (_.isObject(actualErr) && actualErr instanceof Error){ | ||
prettifiedActualErr = actualErr.stack; | ||
} | ||
else { | ||
prettifiedActualErr = util.inspect(args[0], false, null); | ||
} | ||
combinedError += prettifiedActualErr; | ||
} | ||
// Add on the error msg from switchback | ||
if (!_.isUndefined(switchbackErrorMsg)) { | ||
combinedError += ' ' + switchbackErrorMsg; | ||
} | ||
// If a callback fn exists under the '*' or 'error' key in default handlers, call it | ||
if (_.isObject(defaultHandlers)){ | ||
if (_.isFunction(defaultHandlers['*'])) { | ||
return defaultHandlers['*'](combinedError); | ||
} | ||
if (_.isFunction(defaultHandlers.error)) { | ||
return defaultHandlers.error(combinedError); | ||
} | ||
} | ||
// If a callback fn exists under the '*' or 'error' key in Switchback, call it | ||
if (_.isObject(Switchback)){ | ||
if (_.isFunction(Switchback['*'])) { | ||
return Switchback['*'](combinedError); | ||
} | ||
if (_.isFunction(Switchback.error)) { | ||
return Switchback.error(combinedError); | ||
} | ||
} | ||
// console.log('defaultHandlers', defaultHandlers); | ||
// console.log('Switchback', Switchback); | ||
// console.log('Switchback["*"]', Switchback['*']); | ||
// console.log('Switchback["error"]', Switchback['error']); | ||
// Otherwise just throw out of frustration | ||
throw new Error(combinedError); | ||
}; | ||
@@ -122,0 +166,0 @@ }; |
{ | ||
"name": "switchback", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Normalize callback fns to switchbacks and vice versa", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
32296
611
0