Search in sources :

Example 1 with DownloadReviveEvent

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));
    }
}
Also used : DownloadReviveEvent(me.devsaki.hentoid.events.DownloadReviveEvent) ServerError(com.android.volley.ServerError) AuthFailureError(com.android.volley.AuthFailureError) NetworkError(com.android.volley.NetworkError) UserActionNotification(me.devsaki.hentoid.notification.action.UserActionNotification) NoConnectionError(com.android.volley.NoConnectionError) ParseError(com.android.volley.ParseError) TimeoutError(com.android.volley.TimeoutError) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 AuthFailureError (com.android.volley.AuthFailureError)1 NetworkError (com.android.volley.NetworkError)1 NoConnectionError (com.android.volley.NoConnectionError)1 ParseError (com.android.volley.ParseError)1 ServerError (com.android.volley.ServerError)1 TimeoutError (com.android.volley.TimeoutError)1 DownloadReviveEvent (me.devsaki.hentoid.events.DownloadReviveEvent)1 UserActionNotification (me.devsaki.hentoid.notification.action.UserActionNotification)1