Skip to content

Commit 2690fce

Browse files
committed
log internal errors too
1 parent 1148aae commit 2690fce

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

example/src/main/java/com/codepath/example/TestActivity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import com.codepath.asynchttpclient.AsyncHttpClient;
1111
import com.codepath.asynchttpclient.RequestHeaders;
12+
import com.codepath.asynchttpclient.RequestParams;
1213
import com.codepath.asynchttpclient.callback.JsonHttpResponseHandler;
1314
import com.codepath.asynchttpclient.callback.TextHttpResponseHandler;
1415

@@ -24,15 +25,18 @@ protected void onCreate(Bundle savedInstanceState) {
2425

2526
public void onTest(View view) {
2627
AsyncHttpClient cp = new AsyncHttpClient();
27-
cp.get("https://api.thecatapi.com/v1/images/search", new TextHttpResponseHandler() {
28+
RequestParams params = new RequestParams();
29+
params.put("q", "codepath");
30+
31+
cp.get("http://www.google.com/search", params, new TextHttpResponseHandler() {
2832
@Override
2933
public void onSuccess(int statusCode, Headers headers, String response) {
3034
Log.d("DEBUG", response);
3135
}
3236

3337
@Override
3438
public void onFailure(int statusCode, @Nullable Headers headers, String errorResponse, @Nullable Throwable throwable) {
35-
39+
Log.d("DEBUG", errorResponse);
3640
}
3741
});
3842

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
public abstract class JsonHttpResponseHandler implements AbsCallback {
2222

23+
private static int INTERNAL_ERROR = 500;
24+
2325
public abstract void onSuccess(int statusCode, Headers headers, JSON json);
2426

2527
public abstract void onFailure(int statusCode, Headers headers, String response, Throwable throwable);
@@ -39,7 +41,7 @@ public String toString() {
3941

4042
@Override
4143
public void onFailure(@NotNull Call call, @NotNull IOException e) {
42-
44+
this.onFailure(INTERNAL_ERROR, null, e.toString(), e);
4345
}
4446

4547
@Override

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
public abstract class TextHttpResponseHandler implements AbsCallback {
2020

21+
private static int INTERNAL_ERROR = 500;
22+
2123
public TextHttpResponseHandler() {
2224
}
2325

2426
@Override
2527
public void onFailure(@NotNull Call call, @NotNull IOException e) {
26-
28+
this.onFailure(INTERNAL_ERROR, null, e.toString(), e);
2729
}
2830

2931
@Override
@@ -59,7 +61,7 @@ public void run() {
5961
// run on main thread to keep things simple
6062
new Handler(Looper.getMainLooper()).post(runnable);
6163
} catch (IOException e) {
62-
handler.onFailure(500, null, "", e);
64+
handler.onFailure(INTERNAL_ERROR, null, e.toString(), e);
6365
}
6466
}
6567

0 commit comments

Comments
 (0)