Skip to content

Commit bd4cd3a

Browse files
committed
AsyncHttpRequest handle SocketException. Fix issue where responseHandler not notified if link to host offline
1 parent c383108 commit bd4cd3a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/com/loopj/android/http/AsyncHttpRequest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.IOException;
2222
import java.net.ConnectException;
23+
import java.net.SocketException;
2324
import java.net.UnknownHostException;
2425

2526
import org.apache.http.HttpResponse;
@@ -92,11 +93,17 @@ private void makeRequestWithRetries() throws ConnectException {
9293
try {
9394
makeRequest();
9495
return;
95-
} catch (UnknownHostException e) {
96-
if(responseHandler != null) {
97-
responseHandler.sendFailureMessage(e, "can't resolve host");
98-
}
99-
return;
96+
} catch (UnknownHostException e) {
97+
if(responseHandler != null) {
98+
responseHandler.sendFailureMessage(e, "can't resolve host");
99+
}
100+
return;
101+
}catch (SocketException e){
102+
// Added to detect host unreachable
103+
if(responseHandler != null) {
104+
responseHandler.sendFailureMessage(e, "can't resolve host");
105+
}
106+
return;
100107
} catch (IOException e) {
101108
cause = e;
102109
retry = retryHandler.retryRequest(cause, ++executionCount, context);

0 commit comments

Comments
 (0)