Skip to content

Commit 2c2b5e8

Browse files
author
Roger Hu
committedJul 31, 2019
add handler for random ioexceptions
1 parent 9fbb840 commit 2c2b5e8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed
 

‎library/src/main/java/com/codepath/asynchttpclient/callback/AsyncTextCallback.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.os.Handler;
44
import android.os.Looper;
55

6+
import androidx.annotation.Nullable;
7+
68
import com.codepath.asynchttpclient.AbsCallback;
79

810
import org.jetbrains.annotations.NotNull;
@@ -28,18 +30,17 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) {
2830
public void onResponse(@NotNull Call call, @NotNull final Response response)
2931
throws IOException {
3032

33+
final AsyncTextCallback handler = this;
34+
3135
try (final ResponseBody responseBody = response.body()) {
3236

3337
final int responseCode = response.code();
3438
final Headers responseHeaders = response.headers();
3539

36-
final AsyncTextCallback handler = this;
37-
3840
Runnable runnable;
41+
final String responseString = responseBody.string();
3942

4043
if (response.isSuccessful()) {
41-
final String responseString = responseBody.string();
42-
4344
runnable = new Runnable() {
4445
@Override
4546
public void run() {
@@ -50,18 +51,21 @@ public void run() {
5051
runnable = new Runnable() {
5152
@Override
5253
public void run() {
53-
handler.onFailure(responseCode, responseHeaders, responseBody);
54+
handler.onFailure(responseCode, responseHeaders, responseString, null);
5455
}
5556
};
5657
}
5758

5859
// run on main thread to keep things simple
5960
new Handler(Looper.getMainLooper()).post(runnable);
61+
} catch (IOException e) {
62+
handler.onFailure(500, null, "", e);
6063
}
6164
}
6265

6366
public abstract void onSuccess(int statusCode, Headers headers, String response);
6467

65-
public abstract void onFailure(int statusCode, Headers headers, ResponseBody errorResponse);
68+
public abstract void onFailure(int statusCode, @Nullable Headers headers, String errorResponse, @Nullable Throwable e);
69+
6670
}
6771

0 commit comments

Comments
 (0)