cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/2] cordova-plugin-file-transfer git commit: CB-8093 Fixes incorrect FileTransferError returned in case of download failure
Date Fri, 05 Dec 2014 20:22:51 GMT
Repository: cordova-plugin-file-transfer
Updated Branches:
  refs/heads/master 7ee3bcaf5 -> f415f35c2


CB-8093 Fixes incorrect FileTransferError returned in case of download failure


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/80aa8280
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/80aa8280
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/80aa8280

Branch: refs/heads/master
Commit: 80aa82802183f7b9794064fd984b1b646c0ecaaa
Parents: 6fee835
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Thu Nov 27 17:45:42 2014 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Thu Nov 27 18:32:34 2014 +0300

----------------------------------------------------------------------
 src/windows/FileTransferProxy.js | 56 +++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/80aa8280/src/windows/FileTransferProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/FileTransferProxy.js b/src/windows/FileTransferProxy.js
index 0eeef90..273dd65 100644
--- a/src/windows/FileTransferProxy.js
+++ b/src/windows/FileTransferProxy.js
@@ -236,34 +236,40 @@ exec(win, fail, 'FileTransfer', 'upload',
                     successCallback && successCallback(new FileEntry(storageFile.name,
storageFile.path, null, nativeURI));
                 }, function(error) {
 
-                    var result;
-                    // Handle download error here. If download was cancelled,
-                    // message property will be specified
-                    if (error.message == 'Canceled') {
-                        result = new FileTransferError(FileTransferError.ABORT_ERR, source,
target, null, null, error);
-                    } else {
-                        // in the other way, try to get response property
-                        var response = download.getResponseInformation();
-                        if (!response) {
-                            result = new FileTransferError(FileTransferError.CONNECTION_ERR,
source, target);
-                        } else if (response.statusCode == 401 || response.statusCode == 404)
{
-                            result = new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR,
source, target, response.statusCode, null, error);
+                    var getTransferError = new WinJS.Promise(function (resolve) {
+                        // Handle download error here. If download was cancelled,
+                        // message property will be specified
+                        if (error.message === 'Canceled') {
+                            resolve(new FileTransferError(FileTransferError.ABORT_ERR, source,
target, null, null, error));
+                        } else {
+                            // in the other way, try to get response property
+                            var response = download.getResponseInformation();
+                            if (!response) {
+                                resolve(new FileTransferError(FileTransferError.CONNECTION_ERR,
source, target));
+                            } else {
+                                var reader = new Windows.Storage.Streams.DataReader(download.getResultStreamAt(0));
+                                reader.loadAsync(download.progress.bytesReceived).then(function
(bytesLoaded) {
+                                    var payload = reader.readString(bytesLoaded);
+                                    resolve(new FileTransferError(FileTransferError.FILE_NOT_FOUND_ERR,
source, target, response.statusCode, payload, error));
+                                });
+                            }
                         }
-                    }
-
-                    // Update TransferOperation object with new state, delete promise property
-                    // since it is not actual anymore
-                    var currentDownloadOp = fileTransferOps[downloadId];
-                    if (currentDownloadOp) {
-                        currentDownloadOp.state = FileTransferOperation.CANCELLED;
-                        currentDownloadOp.promise = null;
-                    }
-
-                    // Cleanup, remove incompleted file
-                    storageFile.deleteAsync().then(function () {
-                        errorCallback && errorCallback(result);
                     });
+                    getTransferError.then(function (fileTransferError) {
+
+                        // Update TransferOperation object with new state, delete promise
property
+                        // since it is not actual anymore
+                        var currentDownloadOp = fileTransferOps[downloadId];
+                        if (currentDownloadOp) {
+                            currentDownloadOp.state = FileTransferOperation.CANCELLED;
+                            currentDownloadOp.promise = null;
+                        }
 
+                        // Cleanup, remove incompleted file
+                        storageFile.deleteAsync().then(function() {
+                            errorCallback && errorCallback(fileTransferError);
+                        });
+                    });
 
                 }, function(evt) {
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message