@@ -22,7 +22,7 @@ public abstract class AsyncJsonCallback implements AbsCallback {
22
22
23
23
public abstract void onSuccess (int statusCode , Headers headers , JSON json );
24
24
25
- public abstract void onFailure (int statusCode , Headers headers , Throwable errorResponse );
25
+ public abstract void onFailure (int statusCode , Headers headers , String response , Throwable errorResponse );
26
26
27
27
public AsyncJsonCallback () {
28
28
}
@@ -51,9 +51,10 @@ public void onResponse(@NotNull Call call, @NotNull final Response response)
51
51
Runnable runnable ;
52
52
53
53
Handler loopHandler = new Handler (Looper .getMainLooper ());
54
+ final String responseString = responseBody .string ();
55
+
54
56
if (response .isSuccessful ()) {
55
57
try {
56
- String responseString = responseBody .string ();
57
58
final Object jsonResponse = this .parseResponse (responseString );
58
59
59
60
// run on main thread to keep things simple
@@ -70,7 +71,7 @@ public void run() {
70
71
handler .onSuccess (responseCode , responseHeaders , json );
71
72
} else if (jsonResponse instanceof String ) {
72
73
// 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 (
74
75
"Response cannot be parsed as JSON data" + jsonResponse ));
75
76
}
76
77
}
@@ -79,7 +80,7 @@ public void run() {
79
80
runnable = new Runnable () {
80
81
@ Override
81
82
public void run () {
82
- handler .onFailure (responseCode , responseHeaders , null );
83
+ handler .onFailure (responseCode , responseHeaders , responseString , null );
83
84
}
84
85
};
85
86
@@ -88,7 +89,7 @@ public void run() {
88
89
runnable = new Runnable () {
89
90
@ Override
90
91
public void run () {
91
- handler .onFailure (responseCode , responseHeaders ,
92
+ handler .onFailure (responseCode , responseHeaders , responseString ,
92
93
new IllegalStateException ("Response failed" ));
93
94
}
94
95
};
0 commit comments