I'm working with an http-based API and want to know when I encounter any errors. I'm using Android-Query (stub):
AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject json, AjaxStatus status) {
try {
if (json != null) {
if (json.getString("authenticated") != "true")
// An error, but status=200 and json!=null
} catch (JSONException e) { errors... } } };
And I'm using it like this:
final AQuery aq = new AQuery(this);
aq.ajax(url, JSONObject.class, cb);
cb.block();
My questions are:
- I've found that using
cb.block()
is the only way to get the library to work synchronously, but I'm not sure it's the best way (it feels like it isn't). - The callback method can't throw exceptions, can't return anything (void) etc, so what is the best way to handle errors? I noticed it supports
cb.getResult()
but it looks like calling this method causes the outside block to return (I can't explain it).
Thanks.