incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From macdo...@apache.org
Subject [2/2] android commit: Globalization plugin should return an error object and not a code
Date Thu, 27 Sep 2012 15:17:20 GMT
Globalization plugin should return an error object and not a code


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

Branch: refs/heads/master
Commit: 4021f26e76d6c19988d0faabc831242df4683d98
Parents: 1b4096b
Author: Simon MacDonald <simon.macdonald@gmail.com>
Authored: Thu Sep 27 11:16:43 2012 -0400
Committer: Simon MacDonald <simon.macdonald@gmail.com>
Committed: Thu Sep 27 11:16:43 2012 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/Globalization.java      |    2 +-
 .../src/org/apache/cordova/GlobalizationError.java |   17 +++++++++++++++
 2 files changed, 18 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/4021f26e/framework/src/org/apache/cordova/Globalization.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Globalization.java b/framework/src/org/apache/cordova/Globalization.java
index 7d724c9..98bf9e5 100644
--- a/framework/src/org/apache/cordova/Globalization.java
+++ b/framework/src/org/apache/cordova/Globalization.java
@@ -128,7 +128,7 @@ public class Globalization extends Plugin  {
                 return new PluginResult(PluginResult.Status.OK, obj);   
             }           
         }catch (GlobalizationError ge){         
-            return new PluginResult(PluginResult.Status.ERROR, ge.getErrorCode());      
   
+            return new PluginResult(PluginResult.Status.ERROR, ge.toJson());
         }catch (Exception e){           
             return new PluginResult(PluginResult.Status.JSON_EXCEPTION);            
         }   

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/4021f26e/framework/src/org/apache/cordova/GlobalizationError.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/GlobalizationError.java b/framework/src/org/apache/cordova/GlobalizationError.java
index 5c1b09e..8a171d4 100644
--- a/framework/src/org/apache/cordova/GlobalizationError.java
+++ b/framework/src/org/apache/cordova/GlobalizationError.java
@@ -19,6 +19,9 @@
 
 package org.apache.cordova;
 
+import org.json.JSONException;
+import org.json.JSONObject;
+
 /** 
  * @description Exception class representing defined Globalization error codes
  * @Globalization error codes:
@@ -88,4 +91,18 @@ public class GlobalizationError extends Exception{
         return error;
     }
     
+    /**
+     * get the json version of this object to return to javascript
+     * @return
+     */
+    public JSONObject toJson() {
+        JSONObject obj = new JSONObject();
+        try {
+            obj.put("code", getErrorCode());
+            obj.put("message", getErrorString());
+        } catch (JSONException e) {
+            // never happens
+        }
+        return obj;
+    }
 }


Mime
View raw message