Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add example for JSON-RPC returning an error object

A real object could be used as well as a string here, but jsolait
as bundled stringifies the object when it raises a JSONRPCError
exception.
  • Loading branch information...
commit af707a931b846e436e10a38314f6735c5b2141cc 1 parent 908fea6
Paul Hampson authored
Showing with 23 additions and 1 deletion.
  1. +19 −1 www/json_sample.html
  2. +4 −0 www/json_sample.yaws
View
20 www/json_sample.html
@@ -6,7 +6,7 @@
<script>
var serviceURL = "json_sample.yaws";
-var methods = [ "test1" ];
+var methods = [ "test1", "errortest" ];
var jsonrpc = imprt("jsonrpc");
var service = new jsonrpc.ServiceProxy(serviceURL, methods);
@@ -23,6 +23,17 @@
return false;
}
+function errortest() {
+ try {
+ document.getElementById('failure').innerHTML =
+ "<PRE>" + service.errortest() + "</PRE>";
+ } catch(e) {
+ document.getElementById('failure').innerHTML =
+ "<PRE>" + e + "</PRE>";
+ }
+ return false;
+}
+
</script>
<body>
<form action="" method="post" onSubmit="return test()">
@@ -38,5 +49,12 @@
<input type="submit" value="Do JSON-RPC call"/>
</p>
</form>
+ <form action="" method="post" onSubmit="return errortest()">
+ <p>
+ <input type="submit" value="Do JSON-RPC call expected to fail"/>
+ </p>
+ <div id="failure">
+ </div>
+ </form>
</body>
</html>
View
4 www/json_sample.yaws
@@ -16,6 +16,10 @@ out(A) ->
+counter([{ip, IP}] = _State, {call, errortest, Value} = _Request, Session) ->
+ io:format("Request = ~p~n", [_Request]),
+ { false, { error, "Expected failure" } };
+
counter([{ip, IP}] = _State, {call, test1, Value} = _Request, Session) ->
io:format("Request = ~p~n", [_Request]),
IPStr = io_lib:format("Client ip is ~p~n" , [ IP ]),
Please sign in to comment.
Something went wrong with that request. Please try again.