Do not throw exceptions, instead return an object with either a result or an error property.
This commit is contained in:
parent
2f5c368124
commit
6f2647712d
1 changed files with 10 additions and 6 deletions
|
@ -107,13 +107,15 @@ public class XmlRpcObject extends BaseFunction {
|
||||||
throw new JavaScriptException("Invalid method name");
|
throw new JavaScriptException("Invalid method name");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine");
|
||||||
RhinoCore c = engine.core;
|
RhinoCore c = engine.core;
|
||||||
|
Scriptable retval = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
retval = Context.getCurrentContext().newObject(c.global);
|
||||||
XmlRpcClient client = new XmlRpcClient(url);
|
XmlRpcClient client = new XmlRpcClient(url);
|
||||||
|
|
||||||
// long now = System.currentTimeMillis ();
|
// long now = System.currentTimeMillis ();
|
||||||
Object retval = null;
|
|
||||||
int l = args.length;
|
int l = args.length;
|
||||||
Vector v = new Vector();
|
Vector v = new Vector();
|
||||||
|
|
||||||
|
@ -122,9 +124,9 @@ public class XmlRpcObject extends BaseFunction {
|
||||||
v.addElement(arg);
|
v.addElement(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = client.execute(method, v);
|
Object result = client.execute(method, v);
|
||||||
|
|
||||||
return c.processXmlRpcArgument(retval);
|
retval.put("result", retval, c.processXmlRpcArgument(result));
|
||||||
|
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
String msg = x.getMessage();
|
String msg = x.getMessage();
|
||||||
|
@ -132,9 +134,11 @@ public class XmlRpcObject extends BaseFunction {
|
||||||
if ((msg == null) || (msg.length() == 0)) {
|
if ((msg == null) || (msg.length() == 0)) {
|
||||||
msg = x.toString();
|
msg = x.toString();
|
||||||
}
|
}
|
||||||
throw new JavaScriptException(msg);
|
retval.put("error", retval, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClassName() {
|
public String getClassName() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue