@trayio/threadneedle
Advanced tools
Comparing version 1.0.17 to 1.0.19
@@ -8,3 +8,3 @@ /* | ||
module.exports = function (config, body, params) { | ||
module.exports = function (config, body, params, res) { | ||
var threadneedle = this; | ||
@@ -18,3 +18,3 @@ return when.promise(function (resolve, reject) { | ||
if (_.isFunction(threadneedle._globalOptions.afterSuccess) && config.globals !== false) { | ||
return when(threadneedle._globalOptions.afterSuccess(body, params)); | ||
return when(threadneedle._globalOptions.afterSuccess(body, params, res)); | ||
} | ||
@@ -34,3 +34,3 @@ }) | ||
if (_.isFunction(config.afterSuccess)) { | ||
return when(config.afterSuccess(body, params)); | ||
return when(config.afterSuccess(body, params, res)); | ||
} | ||
@@ -37,0 +37,0 @@ }) |
@@ -34,11 +34,4 @@ var when = require('when'); | ||
if (_.isFunction(config)) { | ||
logger.info(methodName+': Running method function.'); | ||
var fnPromise = config.call(threadneedle, params); | ||
if (!_.isFunction(fnPromise.done)) { | ||
throw new Error('Method `'+methodName+'` returns a function that isn\'t a valid promise.'); | ||
} else { | ||
return fnPromise; | ||
} | ||
return when(config.call(threadneedle, params)); | ||
} | ||
@@ -134,3 +127,6 @@ | ||
// If valid, then all good! | ||
resolve(body); | ||
resolve({ | ||
body: body, | ||
response: res | ||
}); | ||
@@ -155,5 +151,5 @@ } | ||
// Handle the after success and failure messages | ||
.done(function (body) { | ||
.done(function (result) { | ||
logger.info(methodName+': running `afterSuccess` hook'); | ||
globalize.afterSuccess.call(threadneedle, config, body, params).done(resolve, reject); | ||
globalize.afterSuccess.call(threadneedle, config, result.body, params, result.response).done(resolve, reject); | ||
}, function (err) { | ||
@@ -160,0 +156,0 @@ logger.info(methodName+': running `afterFailure` hook', err); |
{ | ||
"name": "@trayio/threadneedle", | ||
"version": "1.0.17", | ||
"version": "1.0.19", | ||
"description": "A framework for simplifying working with HTTP-based APIs.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
83198
2205