You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/06/11 22:38:42 UTC

[1/2] git commit: CB-6781: add the exception text to the error object

Repository: cordova-plugin-file-transfer
Updated Branches:
  refs/heads/master 690824248 -> 32106e7a3


CB-6781: add the exception text to the error object


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/46f9c1d4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/46f9c1d4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/46f9c1d4

Branch: refs/heads/master
Commit: 46f9c1d458de7c4f85f2fa19e0020ffb6072651d
Parents: 6908242
Author: ignisvulpis <ax...@nennker.de>
Authored: Thu May 29 20:31:10 2014 +0200
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Jun 11 16:33:39 2014 -0400

----------------------------------------------------------------------
 src/android/FileTransfer.java | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/46f9c1d4/src/android/FileTransfer.java
----------------------------------------------------------------------
diff --git a/src/android/FileTransfer.java b/src/android/FileTransfer.java
index 01d22e0..44a9717 100644
--- a/src/android/FileTransfer.java
+++ b/src/android/FileTransfer.java
@@ -261,7 +261,7 @@ public class FileTransfer extends CordovaPlugin {
         int uriType = CordovaResourceApi.getUriType(targetUri);
         final boolean useHttps = uriType == CordovaResourceApi.URI_TYPE_HTTPS;
         if (uriType != CordovaResourceApi.URI_TYPE_HTTP && !useHttps) {
-            JSONObject error = createFileTransferError(INVALID_URL_ERR, source, target, null, 0);
+            JSONObject error = createFileTransferError(INVALID_URL_ERR, source, target, null, 0, null);
             Log.e(LOG_TAG, "Unsupported URI: " + targetUri);
             callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
             return;
@@ -473,11 +473,11 @@ public class FileTransfer extends CordovaPlugin {
 
                     context.sendPluginResult(new PluginResult(PluginResult.Status.OK, result.toJSONObject()));
                 } catch (FileNotFoundException e) {
-                    JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target, conn);
+                    JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target, conn, e);
                     Log.e(LOG_TAG, error.toString(), e);
                     context.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
                 } catch (IOException e) {
-                    JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, conn);
+                    JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, conn, e);
                     Log.e(LOG_TAG, error.toString(), e);
                     Log.e(LOG_TAG, "Failed after uploading " + totalBytes + " of " + fixedLength + " bytes.");
                     context.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
@@ -486,7 +486,7 @@ public class FileTransfer extends CordovaPlugin {
                     context.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
                 } catch (Throwable t) {
                     // Shouldn't happen, but will
-                    JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, conn);
+                    JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, conn, t);
                     Log.e(LOG_TAG, error.toString(), t);
                     context.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
                 } finally {
@@ -569,7 +569,7 @@ public class FileTransfer extends CordovaPlugin {
         return oldFactory;
     }
 
-    private static JSONObject createFileTransferError(int errorCode, String source, String target, URLConnection connection) {
+    private static JSONObject createFileTransferError(int errorCode, String source, String target, URLConnection connection, Throwable throwable) {
 
         int httpStatus = 0;
         StringBuilder bodyBuilder = new StringBuilder();
@@ -603,7 +603,7 @@ public class FileTransfer extends CordovaPlugin {
             }
         }
 
-        return createFileTransferError(errorCode, source, target, body, httpStatus);
+        return createFileTransferError(errorCode, source, target, body, httpStatus, throwable);
     }
 
         /**
@@ -611,7 +611,7 @@ public class FileTransfer extends CordovaPlugin {
         * @param errorCode      the error
         * @return JSONObject containing the error
         */
-    private static JSONObject createFileTransferError(int errorCode, String source, String target, String body, Integer httpStatus) {
+    private static JSONObject createFileTransferError(int errorCode, String source, String target, String body, Integer httpStatus, Throwable throwable) {
         JSONObject error = null;
         try {
             error = new JSONObject();
@@ -625,6 +625,13 @@ public class FileTransfer extends CordovaPlugin {
             if (httpStatus != null) {
                 error.put("http_status", httpStatus);
             }
+            if (throwable != null) {
+                String msg = throwable.getMessage();
+                if (msg == null || "".equals(msg)) {
+                    msg = throwable.toString();
+                }
+                error.put("exception", msg);
+            }
         } catch (JSONException e) {
             Log.e(LOG_TAG, e.getMessage(), e);
         }
@@ -674,7 +681,7 @@ public class FileTransfer extends CordovaPlugin {
         final boolean useHttps = uriType == CordovaResourceApi.URI_TYPE_HTTPS;
         final boolean isLocalTransfer = !useHttps && uriType != CordovaResourceApi.URI_TYPE_HTTP;
         if (uriType == CordovaResourceApi.URI_TYPE_UNKNOWN) {
-            JSONObject error = createFileTransferError(INVALID_URL_ERR, source, target, null, 0);
+            JSONObject error = createFileTransferError(INVALID_URL_ERR, source, target, null, 0, null);
             Log.e(LOG_TAG, "Unsupported URI: " + targetUri);
             callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
             return;
@@ -683,7 +690,7 @@ public class FileTransfer extends CordovaPlugin {
         // TODO: refactor to also allow resources & content:
         if (!isLocalTransfer && !Config.isUrlWhiteListed(source)) {
             Log.w(LOG_TAG, "Source URL is not in white list: '" + source + "'");
-            JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, null, 401);
+            JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, null, 401, null);
             callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
             return;
         }
@@ -832,18 +839,18 @@ public class FileTransfer extends CordovaPlugin {
                     }
                     
                 } catch (FileNotFoundException e) {
-                    JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target, connection);
+                    JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target, connection, e);
                     Log.e(LOG_TAG, error.toString(), e);
                     result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
                 } catch (IOException e) {
-                    JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection);
+                    JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection, e);
                     Log.e(LOG_TAG, error.toString(), e);
                     result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
                 } catch (JSONException e) {
                     Log.e(LOG_TAG, e.getMessage(), e);
                     result = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
                 } catch (Throwable e) {
-                    JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection);
+                    JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection, e);
                     Log.e(LOG_TAG, error.toString(), e);
                     result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
                 } finally {
@@ -862,7 +869,7 @@ public class FileTransfer extends CordovaPlugin {
                     }
 
                     if (result == null) {
-                        result = new PluginResult(PluginResult.Status.ERROR, createFileTransferError(CONNECTION_ERR, source, target, connection));
+                        result = new PluginResult(PluginResult.Status.ERROR, createFileTransferError(CONNECTION_ERR, source, target, connection, null));
                     }
                     // Remove incomplete download.
                     if (result.getStatus() != PluginResult.Status.OK.ordinal() && file != null) {
@@ -892,7 +899,7 @@ public class FileTransfer extends CordovaPlugin {
                             file.delete();
                         }
                         // Trigger the abort callback immediately to minimize latency between it and abort() being called.
-                        JSONObject error = createFileTransferError(ABORTED_ERR, context.source, context.target, null, -1);
+                        JSONObject error = createFileTransferError(ABORTED_ERR, context.source, context.target, null, -1, null);
                         context.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error));
                         context.aborted = true;
                         if (context.connection != null) {


[2/2] git commit: CB-6781: Continue previous commit with one new instance (This closes #30)

Posted by ia...@apache.org.
CB-6781: Continue previous commit with one new instance (This closes #30)


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/32106e7a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/32106e7a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/32106e7a

Branch: refs/heads/master
Commit: 32106e7a3f6e0b932cb41371260e6f5198c1a6de
Parents: 46f9c1d
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Jun 11 16:34:35 2014 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Jun 11 16:35:13 2014 -0400

----------------------------------------------------------------------
 src/android/FileTransfer.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/32106e7a/src/android/FileTransfer.java
----------------------------------------------------------------------
diff --git a/src/android/FileTransfer.java b/src/android/FileTransfer.java
index 44a9717..c04c0d3 100644
--- a/src/android/FileTransfer.java
+++ b/src/android/FileTransfer.java
@@ -829,7 +829,7 @@ public class FileTransfer extends CordovaPlugin {
                         if (fileEntry != null) {
                             result = new PluginResult(PluginResult.Status.OK, fileEntry);
                         } else {
-                            JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection);
+                            JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection, null);
                             Log.e(LOG_TAG, "File plugin cannot represent download path");
                             result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
                         }