@@ -92,16 +92,17 @@ function headersGetter(headers) {
92
92
* This function is used for both request and response transforming
93
93
*
94
94
* @param {* } data Data to transform.
95
- * @param {function(string=) } headers Http headers getter fn.
95
+ * @param {function(string=) } headers HTTP headers getter fn.
96
+ * @param {number } status HTTP status code of the response.
96
97
* @param {(Function|Array.<Function>) } fns Function or an array of functions.
97
98
* @returns {* } Transformed data.
98
99
*/
99
- function transformData ( data , headers , fns ) {
100
+ function transformData ( data , headers , status , fns ) {
100
101
if ( isFunction ( fns ) )
101
- return fns ( data , headers ) ;
102
+ return fns ( data , headers , status ) ;
102
103
103
104
forEach ( fns , function ( fn ) {
104
- data = fn ( data , headers ) ;
105
+ data = fn ( data , headers , status ) ;
105
106
} ) ;
106
107
107
108
return data ;
@@ -380,7 +381,7 @@ function $HttpProvider() {
380
381
*
381
382
* Both requests and responses can be transformed using transformation functions: `transformRequest`
382
383
* and `transformResponse`. These properties can be a single function that returns
383
- * the transformed value (`{function(data, headersGetter)`) or an array of such transformation functions,
384
+ * the transformed value (`{function(data, headersGetter, status )`) or an array of such transformation functions,
384
385
* which allows you to `push` or `unshift` a new transformation function into the transformation chain.
385
386
*
386
387
* ### Default Transformations
@@ -624,9 +625,9 @@ function $HttpProvider() {
624
625
* See {@link ng.$http#overriding-the-default-transformations-per-request
625
626
* Overriding the Default Transformations}
626
627
* - **transformResponse** –
627
- * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
628
+ * `{function(data, headersGetter, status )|Array.<function(data, headersGetter, status )>}` –
628
629
* transform function or an array of such functions. The transform function takes the http
629
- * response body and headers and returns its transformed (typically deserialized) version.
630
+ * response body, headers and status and returns its transformed (typically deserialized) version.
630
631
* See {@link ng.$http#overriding-the-default-transformations-per-request
631
632
* Overriding the Default Transformations}
632
633
* - **cache** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
@@ -765,7 +766,7 @@ function $HttpProvider() {
765
766
766
767
var serverRequest = function ( config ) {
767
768
var headers = config . headers ;
768
- var reqData = transformData ( config . data , headersGetter ( headers ) , config . transformRequest ) ;
769
+ var reqData = transformData ( config . data , headersGetter ( headers ) , undefined , config . transformRequest ) ;
769
770
770
771
// strip content-type if data is undefined
771
772
if ( isUndefined ( reqData ) ) {
@@ -826,7 +827,7 @@ function $HttpProvider() {
826
827
if ( ! response . data ) {
827
828
resp . data = response . data ;
828
829
} else {
829
- resp . data = transformData ( response . data , response . headers , config . transformResponse ) ;
830
+ resp . data = transformData ( response . data , response . headers , response . status , config . transformResponse ) ;
830
831
}
831
832
return ( isSuccess ( response . status ) )
832
833
? resp
0 commit comments