2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

Adding HTTP status code for transformResponse (#4580)

* Adding HTTP status code for transformResponse

* refs #1214

* Fix wrong argument for tranformResponse

* Fix test wrong argument for tranformData

* Add test case for transformData

* Add test case for transformData (reference headers case)

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Koki Oyatsu
2022-05-10 02:25:16 +09:00
committed by GitHub
parent 9579bad1d3
commit 2f50c8249b
5 changed files with 36 additions and 9 deletions
+3
View File
@@ -36,6 +36,7 @@ module.exports = function dispatchRequest(config) {
config,
config.data,
config.headers,
null,
config.transformRequest
);
@@ -63,6 +64,7 @@ module.exports = function dispatchRequest(config) {
config,
response.data,
response.headers,
response.status,
config.transformResponse
);
@@ -77,6 +79,7 @@ module.exports = function dispatchRequest(config) {
config,
reason.response.data,
reason.response.headers,
reason.response.status,
config.transformResponse
);
}
+3 -2
View File
@@ -8,14 +8,15 @@ var defaults = require('../defaults');
*
* @param {Object|String} data The data to be transformed
* @param {Array} headers The headers for the request or response
* @param {Number} status HTTP status code
* @param {Array|Function} fns A single function or Array of functions
* @returns {*} The resulting transformed data
*/
module.exports = function transformData(data, headers, fns) {
module.exports = function transformData(data, headers, status, fns) {
var context = this || defaults;
/*eslint no-param-reassign:0*/
utils.forEach(fns, function transform(fn) {
data = fn.call(context, data, headers);
data = fn.call(context, data, headers, status);
});
return data;