@@ -43,36 +43,35 @@ function AFSuccess(resolve, task: NSURLSessionDataTask, data?: NSDictionary<stri
4343}
4444
4545function AFFailure ( resolve , reject , task : NSURLSessionDataTask , error : NSError ) {
46- let data : NSDictionary < string , any > & NSData & NSArray < any > = error . userInfo . valueForKey ( AFNetworkingOperationFailingURLResponseDataErrorKey ) ;
47- let parsedData = getData ( data ) ;
48- if ( useLegacy ) {
49- let failure : any = {
50- body : parsedData ,
51- description : error . description ,
52- reason : error . localizedDescription ,
53- url : error . userInfo . objectForKey ( 'NSErrorFailingURLKey' ) . description
54- } ;
55- if ( policies . secured === true ) {
56- failure . description = 'nativescript-https > Invalid SSL certificate! ' + error . description ;
57- }
58- let reason = error . localizedDescription ;
59- let content = parsedData ;
60- resolve ( { task : task , content : content , reason : reason , failure : failure } ) ;
61- } else {
62- let content : any = {
63- body : parsedData ,
64- description : error . description ,
65- reason : error . localizedDescription ,
66- url : error . userInfo . objectForKey ( 'NSErrorFailingURLKey' ) . description
67- } ;
68-
69- if ( policies . secured === true ) {
70- content . description = 'nativescript-https > Invalid SSL certificate! ' + content . description ;
71- }
46+ let data : NSDictionary < string , any > & NSData & NSArray < any > = error . userInfo . valueForKey ( AFNetworkingOperationFailingURLResponseDataErrorKey ) ;
47+ let parsedData = getData ( data ) ;
48+ if ( useLegacy ) {
49+ let failure : any = {
50+ body : parsedData ,
51+ description : error . description ,
52+ reason : error . localizedDescription ,
53+ url : error . userInfo . objectForKey ( 'NSErrorFailingURLKey' ) . description
54+ } ;
55+ if ( policies . secured === true ) {
56+ failure . description = 'nativescript-https > Invalid SSL certificate! ' + error . description ;
57+ }
58+ let reason = error . localizedDescription ;
59+ resolve ( { task : task , content : parsedData , reason : reason , failure : failure } ) ;
60+ } else {
61+ let content : any = {
62+ body : parsedData ,
63+ description : error . description ,
64+ reason : error . localizedDescription ,
65+ url : error . userInfo . objectForKey ( 'NSErrorFailingURLKey' ) . description
66+ } ;
7267
73- let reason = error . localizedDescription ;
74- resolve ( { task , content , reason } ) ;
68+ if ( policies . secured === true ) {
69+ content . description = 'nativescript-https > Invalid SSL certificate! ' + content . description ;
7570 }
71+
72+ let reason = error . localizedDescription ;
73+ resolve ( { task, content, reason} ) ;
74+ }
7675}
7776
7877export function request ( opts : Https . HttpsRequestOptions ) : Promise < Https . HttpsResponse > {
@@ -169,23 +168,23 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
169168}
170169
171170function getData ( data ) {
172- let content : any ;
173- if ( data && data . class ) {
174- if ( data . enumerateKeysAndObjectsUsingBlock || ( < any > data ) instanceof NSArray ) {
175- let serial = NSJSONSerialization . dataWithJSONObjectOptionsError ( data , NSJSONWritingOptions . PrettyPrinted ) ;
176- content = NSString . alloc ( ) . initWithDataEncoding ( serial , NSUTF8StringEncoding ) . toString ( ) ;
177- } else if ( ( < any > data ) instanceof NSData ) {
178- content = NSString . alloc ( ) . initWithDataEncoding ( data , NSASCIIStringEncoding ) . toString ( ) ;
179- } else {
180- content = data ;
181- }
182-
183- try {
184- content = JSON . parse ( content ) ;
185- } catch ( e ) {
186- }
171+ let content : any ;
172+ if ( data && data . class ) {
173+ if ( data . enumerateKeysAndObjectsUsingBlock || ( < any > data ) instanceof NSArray ) {
174+ let serial = NSJSONSerialization . dataWithJSONObjectOptionsError ( data , NSJSONWritingOptions . PrettyPrinted ) ;
175+ content = NSString . alloc ( ) . initWithDataEncoding ( serial , NSUTF8StringEncoding ) . toString ( ) ;
176+ } else if ( ( < any > data ) instanceof NSData ) {
177+ content = NSString . alloc ( ) . initWithDataEncoding ( data , NSASCIIStringEncoding ) . toString ( ) ;
187178 } else {
188- content = data ;
179+ content = data ;
189180 }
190- return content ;
181+
182+ try {
183+ content = JSON . parse ( content ) ;
184+ } catch ( ignore ) {
185+ }
186+ } else {
187+ content = data ;
188+ }
189+ return content ;
191190}
0 commit comments