Globalization plugin should return an error object and not a code

This commit is contained in:
Simon MacDonald 2012-09-27 11:16:43 -04:00
parent 1b4096b01d
commit 4021f26e76
2 changed files with 18 additions and 1 deletions

View File

@ -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);
}

View File

@ -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;
}
}