File tree 3 files changed +9
-11
lines changed
3 files changed +9
-11
lines changed Original file line number Diff line number Diff line change 3
3
@fullName Bad JSON Data
4
4
@description
5
5
6
- The default @{link ng$http#default-transformations `transformResponse`} will try to parse the
6
+ The default @{link ng. $http#default-transformations `transformResponse`} will try to parse the
7
7
response as JSON if the `Content-Type` header is `application/json` or the response looks like a
8
8
valid JSON-stringified object or array.
9
9
This error occurs when that data is not a valid JSON object.
10
10
11
11
The error message should provide additional context such as the actual response.
12
12
13
- To resolve this error, make sure you pass a valid JSON data object to `transformResponse`.
14
-
15
- For more information, see the {@link ng$http#default-transformations `transformResponse`} service
16
- API documentation.
13
+ To resolve this error, make sure you pass valid JSON data to `transformResponse` or use an
14
+ appropriate `Content-Type` header for non-JSON data.
Original file line number Diff line number Diff line change @@ -142,7 +142,7 @@ function defaultHttpResponseTransform(data, headers) {
142
142
data = fromJson ( tempData ) ;
143
143
} catch ( e ) {
144
144
throw $httpMinErr ( 'baddata' , 'Data must be a valid JSON object. Received: "{0}". ' +
145
- 'Error occurred : "{1}"' , data , e ) ;
145
+ 'Parse error : "{1}"' , data , e ) ;
146
146
}
147
147
}
148
148
}
Original file line number Diff line number Diff line change @@ -1446,12 +1446,12 @@ describe('$http', function() {
1446
1446
it ( 'should return JSON data with error message if JSON is invalid' , function ( ) {
1447
1447
var errCallback = jasmine . createSpy ( 'error' ) ;
1448
1448
$httpBackend . expect ( 'GET' , '/url' ) . respond ( '{abcd}' , { 'Content-Type' : 'application/json' } ) ;
1449
- $http ( { method : 'GET' , url : ' /url'} ) . then ( callback ) . catch ( errCallback ) ;
1450
- $httpBackend . flush ( ) ;
1449
+ $http . get ( ' /url') . then ( callback ) . catch ( errCallback ) ;
1450
+ $httpBackend . flush ( ) ;
1451
1451
1452
- expect ( callback ) . not . toHaveBeenCalled ( ) ;
1453
- expect ( errCallback ) . toHaveBeenCalledOnce ( ) ;
1454
- expect ( errCallback . calls . mostRecent ( ) . args [ 0 ] ) . toEqualMinErr ( '$http' , 'baddata' ) ;
1452
+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
1453
+ expect ( errCallback ) . toHaveBeenCalledOnce ( ) ;
1454
+ expect ( errCallback . calls . mostRecent ( ) . args [ 0 ] ) . toEqualMinErr ( '$http' , 'baddata' ) ;
1455
1455
} ) ;
1456
1456
} ) ;
1457
1457
} ) ;
You can’t perform that action at this time.
0 commit comments