File tree 2 files changed +18
-1
lines changed
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change
1
+ @ngdoc error
2
+ @name $http:baddata
3
+ @fullName Bad JSON Data
4
+ @description
5
+
6
+ This error occurs when the data parameter passed to the {@link ng.$http `defaultHttpResponseTransform`} service is not a valid JSON object.
7
+ `defaultHttpResponseTransform` expects the first parameter as a valid JSON object if the second parameter of headers specifies a Content-Type of JSON.
8
+
9
+ The error message should provide additional context such as the actual value of the parameter that was received.
10
+
11
+ To resolve this error, make sure you pass a valid JSON data object to `defaultHttpResponseTransform`.
12
+
13
+ For more information, see the {@link ng.$http `defaultHttpResponseTransform`} service API documentation.
Original file line number Diff line number Diff line change @@ -138,7 +138,11 @@ function defaultHttpResponseTransform(data, headers) {
138
138
if ( tempData ) {
139
139
var contentType = headers ( 'Content-Type' ) ;
140
140
if ( ( contentType && ( contentType . indexOf ( APPLICATION_JSON ) === 0 ) ) || isJsonLike ( tempData ) ) {
141
- data = fromJson ( tempData ) ;
141
+ try {
142
+ data = fromJson ( tempData ) ;
143
+ } catch ( e ) {
144
+ throw minErr ( '$http' ) ( 'baddata' , 'Data must be a valid JSON object. Received: {0}' , data ) ;
145
+ }
142
146
}
143
147
}
144
148
}
You can’t perform that action at this time.
0 commit comments