Skip to content

Commit 1d5642c

Browse files
author
Sefa Ilkimen
committed
fix silkimen#83: handle error during file download correctly on iOS
1 parent a580ce2 commit 1d5642c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/ios/CordovaHttpPlugin.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command {
517517
} failure:^(NSURLSessionTask *task, NSError *error) {
518518
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
519519
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
520+
[dictionary setObject:@"There was an error downloading the file" forKey:@"error"];
520521

521522
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
522523
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

test/app-test-definitions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,15 @@ const tests = [
455455
result.type.should.be.equal('resolved');
456456
JSON.parse(result.data.data).headers['Content-Type'].should.be.equal('text/plain');
457457
}
458+
},{
459+
description: 'should handle error during file download correctly (DOWNLOAD) #83',
460+
expected: 'rejected: {"status": 403, "error": "There was an error downloading the file" ...',
461+
func: function(resolve, reject) { cordova.plugin.http.downloadFile('http://httpbin.org/status/403', {}, {}, cordova.file.tempDirectory + 'testfile.txt', resolve, reject); },
462+
validationFunc: function(driver, result) {
463+
result.type.should.be.equal('rejected');
464+
result.data.status.should.be.equal(403);
465+
result.data.error.should.be.equal('There was an error downloading the file');
466+
}
458467
}
459468
];
460469

0 commit comments

Comments
 (0)