Skip to content

Commit

Permalink
Set exception cause when re-raising IOException
Browse files Browse the repository at this point in the history
This allows to execute custom logic in AsyncHttpResponseHandler.onFailure
for specific errors, e.g. to display a nicer error message to the user when
there is a DNS resolution failure, instead of leaking a useless and verbose
UnknownHostException in the UI.
  • Loading branch information
whitequark committed Feb 26, 2016
1 parent 9c7b6d4 commit effd954
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void makeRequestWithRetries() throws IOException {
// switching between WI-FI and mobile data networks can cause a retry which then results in an UnknownHostException
// while the WI-FI is initialising. The retry logic will be invoked here, if this is NOT the first retry
// (to assist in genuine cases of unknown host) which seems better than outright failure
cause = new IOException("UnknownHostException exception: " + e.getMessage());
cause = new IOException("UnknownHostException exception: " + e.getMessage(), e);
retry = (executionCount > 0) && retryHandler.retryRequest(e, ++executionCount, context);
} catch (NullPointerException e) {
// there's a bug in HttpClient 4.0.x that on some occasions causes
Expand All @@ -203,7 +203,7 @@ private void makeRequestWithRetries() throws IOException {
} catch (Exception e) {
// catch anything else to ensure failure message is propagated
AsyncHttpClient.log.e("AsyncHttpRequest", "Unhandled exception origin cause", e);
cause = new IOException("Unhandled exception: " + e.getMessage());
cause = new IOException("Unhandled exception: " + e.getMessage(), cause);
}

// cleaned up to throw IOException
Expand Down

0 comments on commit effd954

Please sign in to comment.