@@ -5,6 +5,7 @@ import * as fileSystemModule from "tns-core-modules/file-system";
55const main_queue = dispatch_get_current_queue ( ) ;
66let zonedOnProgress = null ;
77let zonedOnError = null ;
8+ let previousResponse = null ;
89
910function onProgress ( nsSession , nsTask , sent , expectedTotal ) {
1011 const task = Task . getTask ( nsSession , nsTask ) ;
@@ -24,14 +25,16 @@ function onError(session, nsTask, error) {
2425 NSFileManager . defaultManager . removeItemAtPathError ( task . _fileToCleanup ) ;
2526 }
2627 const response = nsTask && < NSHTTPURLResponse > nsTask . performSelector ( "response" ) ;
27- if ( error ) {
28+ const hasResponseStatusError = response && response . statusCode >= 400 || false ;
29+
30+ if ( error || hasResponseStatusError ) {
2831 task . notifyPropertyChange ( "status" , task . status ) ;
2932 task . notify ( < common . ErrorEventData > {
3033 eventName : "error" ,
3134 object : task ,
3235 error,
3336 responseCode : response ? response . statusCode : - 1 ,
34- response
37+ response : previousResponse || null
3538 } ) ;
3639 } else {
3740 task . notifyPropertyChange ( "upload" , task . upload ) ;
@@ -110,11 +113,12 @@ class BackgroundUploadDelegate extends NSObject implements NSURLSessionDelegate,
110113 // we have a response in the data...
111114 const jsTask = Task . getTask ( session , dataTask ) ;
112115 const jsonString = NSString . alloc ( ) . initWithDataEncoding ( data , NSUTF8StringEncoding ) ;
116+ previousResponse = jsonString . toString ( ) ;
113117
114118 jsTask . notify ( < common . ResultEventData > {
115119 eventName : "responded" ,
116120 object : jsTask ,
117- data : jsonString . toString ( ) ,
121+ response : jsonString . toString ( ) ,
118122 responseCode : dataTask && dataTask . response ? ( < NSHTTPURLResponse > dataTask . response ) . statusCode : - 1
119123 } ) ;
120124 } ) ;
0 commit comments