Skip to content

Commit 78ad2d3

Browse files
author
Roger Hu
committed
add String to response
1 parent 3638938 commit 78ad2d3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

library/src/main/java/com/codepath/asynchttpclient/callback/AsyncJsonCallback.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public abstract class AsyncJsonCallback implements AbsCallback {
2222

2323
public abstract void onSuccess(int statusCode, Headers headers, JSON json);
2424

25-
public abstract void onFailure(int statusCode, Headers headers, Throwable errorResponse);
25+
public abstract void onFailure(int statusCode, Headers headers, String response, Throwable errorResponse);
2626

2727
public AsyncJsonCallback() {
2828
}
@@ -51,9 +51,10 @@ public void onResponse(@NotNull Call call, @NotNull final Response response)
5151
Runnable runnable;
5252

5353
Handler loopHandler = new Handler(Looper.getMainLooper());
54+
final String responseString = responseBody.string();
55+
5456
if (response.isSuccessful()) {
5557
try {
56-
String responseString = responseBody.string();
5758
final Object jsonResponse = this.parseResponse(responseString);
5859

5960
// run on main thread to keep things simple
@@ -70,7 +71,7 @@ public void run() {
7071
handler.onSuccess(responseCode, responseHeaders, json);
7172
} else if (jsonResponse instanceof String) {
7273
// In RFC5179 a simple string value is not a valid JSON
73-
handler.onFailure(responseCode, responseHeaders, new JSONException(
74+
handler.onFailure(responseCode, responseHeaders, responseString, new JSONException(
7475
"Response cannot be parsed as JSON data" + jsonResponse));
7576
}
7677
}
@@ -79,7 +80,7 @@ public void run() {
7980
runnable = new Runnable() {
8081
@Override
8182
public void run() {
82-
handler.onFailure(responseCode, responseHeaders, null);
83+
handler.onFailure(responseCode, responseHeaders, responseString, null);
8384
}
8485
};
8586

@@ -88,7 +89,7 @@ public void run() {
8889
runnable = new Runnable() {
8990
@Override
9091
public void run() {
91-
handler.onFailure(responseCode, responseHeaders,
92+
handler.onFailure(responseCode, responseHeaders, responseString,
9293
new IllegalStateException("Response failed"));
9394
}
9495
};

0 commit comments

Comments
 (0)