diff --git a/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java b/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java index 59048e144..7f0150380 100644 --- a/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java +++ b/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java @@ -192,6 +192,12 @@ private boolean isCancelled() { } private void nextTask(final int offset, final int retried, final URI address) { + if (isCancelled()) { + ResponseInfo i = ResponseInfo.cancelled(); + completionHandler.complete(key, i, null); + return; + } + if (offset == size) { CompletionHandler complete = new CompletionHandler() { @Override @@ -203,13 +209,7 @@ public void complete(ResponseInfo info, JSONObject response) { return; } - if (isCancelled()) { - ResponseInfo i = ResponseInfo.cancelled(); - completionHandler.complete(key, i, null); - return; - } - - if (isNotQiniu(info) || (info.needRetry() && retried < config.retryMax)) { + if ((isNotQiniu(info) || info.needRetry()) && retried < config.retryMax) { nextTask(offset, retried + 1, config.upBackup.address); return; } @@ -236,27 +236,22 @@ public void onProgress(int bytesWritten, int totalSize) { @Override public void complete(ResponseInfo info, JSONObject response) { if (!info.isOK()) { - if (isCancelled()) { - ResponseInfo i = ResponseInfo.cancelled(); - completionHandler.complete(key, i, null); - return; - } - if (info.statusCode == 701) { - nextTask((offset / Configuration.BLOCK_SIZE) * Configuration.BLOCK_SIZE, retried, address); + if (info.statusCode == 701 && retried < config.retryMax) { + nextTask((offset / Configuration.BLOCK_SIZE) * Configuration.BLOCK_SIZE, retried + 1, address); return; } - if (!isNotQiniu(info) && (retried >= config.retryMax || !info.needRetry())) { - completionHandler.complete(key, info, null); + if ((isNotQiniu(info) || info.needRetry()) && retried < config.retryMax) { + nextTask(offset, retried + 1, config.upBackup.address); return; } - nextTask(offset, retried + 1, config.upBackup.address); + completionHandler.complete(key, info, response); return; } String context = null; - if (response == null) { + if (response == null && retried < config.retryMax) { nextTask(offset, retried + 1, config.upBackup.address); return; } @@ -267,7 +262,7 @@ public void complete(ResponseInfo info, JSONObject response) { } catch (JSONException e) { e.printStackTrace(); } - if (context == null || crc != ResumeUploader.this.crc32) { + if ((context == null || crc != ResumeUploader.this.crc32) && retried < config.retryMax) { nextTask(offset, retried + 1, config.upBackup.address); return; }