-
8 Mar 2013 2:12 AM #1
Should HttpProxy catch Exeption thrown by callback.onSuccess method?
Should HttpProxy catch Exeption thrown by callback.onSuccess method?
The current implementation would not be able to catch exception thrown by 'callback.onSuccess(....)' method. Should we catch it and forward the exception to 'callback.onFailure(....)' method?Code:@Override public void load(final C loadConfig, final Callback<String, Throwable> callback) { try { String data = null; if (shouldUseBody()) { data = generateUrl(loadConfig); } else { StringBuilder url = new StringBuilder(initUrl); url.append(url.indexOf("?") == -1 ? "?" : "&"); String params = generateUrl(loadConfig); url.append(params); setUrl(builder, url.toString()); } builder.sendRequest(data, new RequestCallback() { @Override public void onError(Request request, Throwable exception) { callback.onFailure(exception); } @Override public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() != Response.SC_OK) { callback.onFailure(new RuntimeException("HttpProxy: Invalid status code " + response.getStatusCode())); return; } callback.onSuccess(response.getText()); // <-- Exception thrown here // would not be caught... } }); } catch (Exception e) { callback.onFailure(e); // <-- this catch block does not catch // all possible exceptions. } }
Thank you for reporting this bug. We will make it our priority to review this report.


Reply With Quote