use of me.devsaki.hentoid.events.DownloadReviveEvent in project Hentoid by avluis.
the class ContentDownloadWorker method onRequestError.
private void onRequestError(VolleyError error, @NonNull Content content, @NonNull ImageFile img, @NonNull DocumentFile dir, @NonNull String backupUrl, @NonNull Map<String, String> requestHeaders) {
// If the queue is being reset, ignore the error
if (requestQueueManager.isInit())
return;
// Try with the backup URL, if it exists and if the current image isn't a backup itself
if (!img.isBackup() && !backupUrl.isEmpty()) {
tryUsingBackupUrl(img, dir, backupUrl, requestHeaders);
return;
}
// If no backup, then process the error
int statusCode = (error.networkResponse != null) ? error.networkResponse.statusCode : -1;
String message = error.getMessage() + (img.isBackup() ? " (from backup URL)" : "");
String cause = "";
if (error instanceof TimeoutError) {
cause = "Timeout";
} else if (error instanceof NoConnectionError) {
cause = "No connection";
} else if (error instanceof AuthFailureError) {
// 403's fall in this category
cause = "Auth failure";
} else if (error instanceof ServerError) {
// 404's fall in this category
cause = "Server error";
} else if (error instanceof NetworkError) {
cause = "Network error";
} else if (error instanceof ParseError) {
cause = "Network parse error";
}
Timber.d(error);
updateImageProperties(img, false, "");
logErrorRecord(content.getId(), ErrorType.NETWORKING, img.getUrl(), img.getName(), cause + "; HTTP statusCode=" + statusCode + "; message=" + message);
// Handle cloudflare blocks
if (content.getSite().isUseCloudflare() && 503 == statusCode && !isCloudFlareBlocked) {
// prevent associated events & notifs to be fired more than once
isCloudFlareBlocked = true;
EventBus.getDefault().post(DownloadEvent.fromPauseMotive(DownloadEvent.Motive.STALE_CREDENTIALS));
dao.clearDownloadParams(content.getId());
final String cfCookie = StringHelper.protect(HttpHelper.parseCookies(HttpHelper.getCookies(img.getUrl())).get(Consts.CLOUDFLARE_COOKIE));
userActionNotificationManager.notify(new UserActionNotification(content.getSite(), cfCookie));
if (HentoidApp.isInForeground())
EventBus.getDefault().post(new DownloadReviveEvent(content.getSite(), cfCookie));
}
}
Aggregations