You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/06/14 23:42:08 UTC

js commit: [CB-790] Adding HTTP status codes, source and target properties to FileTransferError

Updated Branches:
  refs/heads/master 97e4a5cb9 -> f8fa7c8f5


[CB-790] Adding HTTP status codes, source and target properties to FileTransferError


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/f8fa7c8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/f8fa7c8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/f8fa7c8f

Branch: refs/heads/master
Commit: f8fa7c8f54c1c5401ccf325da8bd937f8225b745
Parents: 97e4a5c
Author: Fil Maj <ma...@gmail.com>
Authored: Thu Jun 14 14:42:14 2012 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu Jun 14 14:42:14 2012 -0700

----------------------------------------------------------------------
 lib/common/plugin/FileTransfer.js      |   16 ++++++++++++++--
 lib/common/plugin/FileTransferError.js |    7 +++++--
 2 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/f8fa7c8f/lib/common/plugin/FileTransfer.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/FileTransfer.js b/lib/common/plugin/FileTransfer.js
index 8742956..c92137d 100644
--- a/lib/common/plugin/FileTransfer.js
+++ b/lib/common/plugin/FileTransfer.js
@@ -1,4 +1,5 @@
-var exec = require('cordova/exec');
+var exec = require('cordova/exec'),
+    FileTransferError = require('cordova/plugin/FileTransferError');
 
 /**
  * FileTransfer uploads a file to a remote server.
@@ -38,7 +39,12 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
         }
     }
 
-    exec(successCallback, errorCallback, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode]);
+    var fail = function(e) {
+        var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
+        errorCallback(error);
+    };
+
+    exec(successCallback, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode]);
 };
 
 /**
@@ -63,6 +69,12 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro
         entry.fullPath = result.fullPath;
         successCallback(entry);
     };
+
+    var fail = function(e) {
+        var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
+        errorCallback(error);
+    };
+
     exec(win, errorCallback, 'FileTransfer', 'download', [source, target]);
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/f8fa7c8f/lib/common/plugin/FileTransferError.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/FileTransferError.js b/lib/common/plugin/FileTransferError.js
index 8c9a7dd..8e0c0fb 100644
--- a/lib/common/plugin/FileTransferError.js
+++ b/lib/common/plugin/FileTransferError.js
@@ -2,12 +2,15 @@
  * FileTransferError
  * @constructor
  */
-var FileTransferError = function(code) {
+var FileTransferError = function(code, source, target, status) {
     this.code = code || null;
+    this.source = source || null;
+    this.target = target || null;
+    this.http_status = status || null;
 };
 
 FileTransferError.FILE_NOT_FOUND_ERR = 1;
 FileTransferError.INVALID_URL_ERR = 2;
 FileTransferError.CONNECTION_ERR = 3;
 
-module.exports = FileTransferError;
\ No newline at end of file
+module.exports = FileTransferError;