Download file only if the server replies with success code

This commit is contained in:
Gabriele M
2017-07-04 19:05:04 +02:00
parent c4c5a72c75
commit fe3d8be858

View File

@@ -154,6 +154,10 @@ public class DownloadClient {
downloadFileInternalCommon(request, destination, callback, progressListener);
}
private boolean isSuccessful(int statusCode) {
return (statusCode / 100) == 2;
}
private void downloadFileInternalCommon(final Request request, final File destination,
final DownloadCallback callback, final ProgressListener progressListener) {
@@ -185,6 +189,10 @@ public class DownloadClient {
if (resume) {
mResumeOffset = destination.length();
Log.d(TAG, "The server fulfilled the partial content request");
} else if (!isSuccessful(response.code())) {
Log.e(TAG, "The server replied with code " + response.code());
callback.onFailure();
return;
}
callback.onResponse(response.code(), response.request().urlString(),