3
3
import android .os .Handler ;
4
4
import android .os .Looper ;
5
5
6
+ import androidx .annotation .Nullable ;
7
+
6
8
import com .codepath .asynchttpclient .AbsCallback ;
7
9
8
10
import org .jetbrains .annotations .NotNull ;
@@ -28,18 +30,17 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) {
28
30
public void onResponse (@ NotNull Call call , @ NotNull final Response response )
29
31
throws IOException {
30
32
33
+ final AsyncTextCallback handler = this ;
34
+
31
35
try (final ResponseBody responseBody = response .body ()) {
32
36
33
37
final int responseCode = response .code ();
34
38
final Headers responseHeaders = response .headers ();
35
39
36
- final AsyncTextCallback handler = this ;
37
-
38
40
Runnable runnable ;
41
+ final String responseString = responseBody .string ();
39
42
40
43
if (response .isSuccessful ()) {
41
- final String responseString = responseBody .string ();
42
-
43
44
runnable = new Runnable () {
44
45
@ Override
45
46
public void run () {
@@ -50,18 +51,21 @@ public void run() {
50
51
runnable = new Runnable () {
51
52
@ Override
52
53
public void run () {
53
- handler .onFailure (responseCode , responseHeaders , responseBody );
54
+ handler .onFailure (responseCode , responseHeaders , responseString , null );
54
55
}
55
56
};
56
57
}
57
58
58
59
// run on main thread to keep things simple
59
60
new Handler (Looper .getMainLooper ()).post (runnable );
61
+ } catch (IOException e ) {
62
+ handler .onFailure (500 , null , "" , e );
60
63
}
61
64
}
62
65
63
66
public abstract void onSuccess (int statusCode , Headers headers , String response );
64
67
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
+
66
70
}
67
71
0 commit comments