switchback
Advanced tools
Comparing version 1.1.3 to 2.0.0
@@ -44,3 +44,13 @@ /** | ||
if (_.isObject(err) && _.isString(err.exit) && _.isFunction(_switch[err.exit])) { | ||
return _switch[err.exit].apply(callbackContext || this, args); | ||
// Also, if we're able to do this (i.e. a callback was supplied for this "exit") | ||
// then check to see if there was also an `.output` property provided. | ||
// If so, use it as the first argument when triggering the callback. | ||
if (!_.isUndefined(err.output)) { | ||
return _switch[err.exit].apply(callbackContext || this, [err.output]); | ||
} | ||
// Otherwise, just use the err object as-is. | ||
// (TODO: in `machine`, consider using the description, other metadata, etc.) | ||
else { | ||
return _switch[err.exit].apply(callbackContext || this, args); | ||
} | ||
} | ||
@@ -56,3 +66,3 @@ return _switch.error.apply(callbackContext || this, args); | ||
// Mix in non-enumerable `.inspect()` method | ||
Object.defineProperty(this, 'inspect', { enumerable: false, writable: true }); | ||
Object.defineProperty(_switch, 'inspect', { enumerable: false, writable: true }); | ||
_switch.inspect = function () { return '[Switchback]'; }; | ||
@@ -59,0 +69,0 @@ |
@@ -110,2 +110,5 @@ /** | ||
// This is here as a failsafe to solve issues when no error callback is specified. | ||
var MAX_WILDCARD_FWDS = 15; | ||
var numWildcardFwds = 0; | ||
@@ -140,2 +143,8 @@ // Supply a handful of default handlers to provide better error messages. | ||
// Before attempting to call error handler, ensure that we're not | ||
// in an infinite loop. | ||
if (numWildcardFwds > MAX_WILDCARD_FWDS) { | ||
throw new Error('Switchback: handlers object (' + util.inspect(defaultHandlers) + ') has a cyclic redirect.'); | ||
} | ||
// If a callback fn exists under the '*' or 'error' key in default handlers, call it | ||
@@ -142,0 +151,0 @@ if (_.isObject(defaultHandlers)){ |
{ | ||
"name": "switchback", | ||
"version": "1.1.3", | ||
"version": "2.0.0", | ||
"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
33264
629