From cf293642fbf4216e479c3dfad848896a2f8c2603 Mon Sep 17 00:00:00 2001 From: inorichi Date: Thu, 14 Mar 2019 21:44:20 +0100 Subject: [PATCH] Fix Glide exceptions --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 16 ++++++++++------ .../tachiyomi/network/CloudflareInterceptor.kt | 9 ++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 0219f98d9..18e6dff24 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -57,13 +57,17 @@ open class App : Application() { } protected open fun setupJobManager() { - JobManager.create(this).addJobCreator { tag -> - when (tag) { - LibraryUpdateJob.TAG -> LibraryUpdateJob() - UpdaterJob.TAG -> UpdaterJob() - BackupCreatorJob.TAG -> BackupCreatorJob() - else -> null + try { + JobManager.create(this).addJobCreator { tag -> + when (tag) { + LibraryUpdateJob.TAG -> LibraryUpdateJob() + UpdaterJob.TAG -> UpdaterJob() + BackupCreatorJob.TAG -> BackupCreatorJob() + else -> null + } } + } catch (e: Exception) { + Timber.w("Can't initialize job manager") } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt index 0824e9b6d..5bee37cab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.network import com.squareup.duktape.Duktape import okhttp3.* +import java.io.IOException class CloudflareInterceptor : Interceptor { @@ -19,7 +20,13 @@ class CloudflareInterceptor : Interceptor { // Check if Cloudflare anti-bot is on if (response.code() == 503 && response.header("Server") in serverCheck) { - return chain.proceed(resolveChallenge(response)) + return try { + chain.proceed(resolveChallenge(response)) + } catch (e: Exception) { + // Because OkHttp's enqueue only handles IOExceptions, wrap the exception so that + // we don't crash the entire app + throw IOException(e) + } } return response