Skip to content

Commit 19e73fa

Browse files
committed
Safely wrapping around onProgress, so it doesn't interrupt communication, Closes android-async-http#356
1 parent 418f508 commit 19e73fa

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

library/src/com/loopj/android/http/AsyncHttpResponseHandler.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,19 @@ protected void handleMessage(Message msg) {
342342
switch (msg.what) {
343343
case SUCCESS_MESSAGE:
344344
response = (Object[]) msg.obj;
345-
if (response != null && response.length >= 3)
345+
if (response != null && response.length >= 3) {
346346
onSuccess((Integer) response[0], (Header[]) response[1], (byte[]) response[2]);
347-
else
347+
} else {
348348
Log.e(LOG_TAG, "SUCCESS_MESSAGE didn't got enough params");
349+
}
349350
break;
350351
case FAILURE_MESSAGE:
351352
response = (Object[]) msg.obj;
352-
if (response != null && response.length >= 4)
353+
if (response != null && response.length >= 4) {
353354
onFailure((Integer) response[0], (Header[]) response[1], (byte[]) response[2], (Throwable) response[3]);
354-
else
355+
} else {
355356
Log.e(LOG_TAG, "FAILURE_MESSAGE didn't got enough params");
357+
}
356358
break;
357359
case START_MESSAGE:
358360
onStart();
@@ -362,10 +364,15 @@ protected void handleMessage(Message msg) {
362364
break;
363365
case PROGRESS_MESSAGE:
364366
response = (Object[]) msg.obj;
365-
if (response != null && response.length >= 2)
366-
onProgress((Integer) response[0], (Integer) response[1]);
367-
else
367+
if (response != null && response.length >= 2) {
368+
try {
369+
onProgress((Integer) response[0], (Integer) response[1]);
370+
} catch (Throwable t) {
371+
Log.e(LOG_TAG, "custom onProgress contains an error", t);
372+
}
373+
} else {
368374
Log.e(LOG_TAG, "PROGRESS_MESSAGE didn't got enough params");
375+
}
369376
break;
370377
case RETRY_MESSAGE:
371378
onRetry();

0 commit comments

Comments
 (0)