File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -283,12 +283,21 @@ class NSURLSessionTaskDelegateImpl extends NSObject
283
283
let responseText ;
284
284
if ( isTextContentType ( returnType ) ) {
285
285
responseText = NSDataToString ( this . _data ) ;
286
- content = NSDataToString ( responseText ) ;
286
+ content = responseText ;
287
287
} else if ( returnType . indexOf ( 'application/json' ) > - 1 ) {
288
288
// @ts -ignore
289
- responseText = NSDataToString ( this . _data ) ;
290
- content = JSON . parse ( responseText ) ;
291
- // content = deserialize(NSJSONSerialization.JSONObjectWithDataOptionsError(this._data, NSJSONReadingOptions.AllowFragments, null));
289
+ try {
290
+ responseText = NSDataToString ( this . _data ) ;
291
+ content = JSON . parse ( responseText ) ;
292
+ // content = deserialize(NSJSONSerialization.JSONObjectWithDataOptionsError(this._data, NSJSONReadingOptions.AllowFragments, null));
293
+ } catch ( err ) {
294
+ this . _reject ( {
295
+ type : HttpError . Error ,
296
+ ios : null ,
297
+ message : err
298
+ } ) ;
299
+ return ;
300
+ }
292
301
} else {
293
302
content = this . _data ;
294
303
}
Original file line number Diff line number Diff line change @@ -426,7 +426,11 @@ export class TNSXMLHttpRequest {
426
426
if ( this . responseType === XMLHttpRequestResponseType . json ) {
427
427
if ( typeof res . content === 'string' ) {
428
428
this . _responseText = res . content ;
429
- this . _response = JSON . parse ( this . responseText ) ;
429
+ try {
430
+ this . _response = JSON . parse ( this . responseText ) ;
431
+ } catch ( err ) {
432
+ // this should probably be caught before the promise resolves
433
+ }
430
434
} else if ( typeof res . content === 'object' ) {
431
435
this . _response = res . content ;
432
436
this . _responseText = res . responseText ;
You can’t perform that action at this time.
0 commit comments