diff --git a/src/ios/CordovaHttpPlugin.m b/src/ios/CordovaHttpPlugin.m index bc9942e..8277a27 100644 --- a/src/ios/CordovaHttpPlugin.m +++ b/src/ios/CordovaHttpPlugin.m @@ -517,6 +517,7 @@ } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error]; + [dictionary setObject:@"There was an error downloading the file" forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; diff --git a/test/app-test-definitions.js b/test/app-test-definitions.js index 8f36356..0503053 100644 --- a/test/app-test-definitions.js +++ b/test/app-test-definitions.js @@ -455,6 +455,15 @@ const tests = [ result.type.should.be.equal('resolved'); JSON.parse(result.data.data).headers['Content-Type'].should.be.equal('text/plain'); } + },{ + description: 'should handle error during file download correctly (DOWNLOAD) #83', + expected: 'rejected: {"status": 403, "error": "There was an error downloading the file" ...', + func: function(resolve, reject) { cordova.plugin.http.downloadFile('http://httpbin.org/status/403', {}, {}, cordova.file.tempDirectory + 'testfile.txt', resolve, reject); }, + validationFunc: function(driver, result) { + result.type.should.be.equal('rejected'); + result.data.status.should.be.equal(403); + result.data.error.should.be.equal('There was an error downloading the file'); + } } ];