From a1554f81ff1c99708d0ef666c7d7540ed7439073 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sat, 19 Aug 2023 18:02:22 +0300 Subject: [PATCH] Fix cover restoration --- .../org/koitharu/kotatsu/main/domain/CoverRestorer.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/main/domain/CoverRestorer.kt b/app/src/main/kotlin/org/koitharu/kotatsu/main/domain/CoverRestorer.kt index 0471a1cdc..d1541c60c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/main/domain/CoverRestorer.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/main/domain/CoverRestorer.kt @@ -7,6 +7,7 @@ import coil.network.HttpException import coil.request.ErrorResult import coil.request.ImageRequest import kotlinx.coroutines.launch +import org.jsoup.HttpStatusException import org.koitharu.kotatsu.bookmarks.domain.Bookmark import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository import org.koitharu.kotatsu.core.parser.MangaDataRepository @@ -14,6 +15,7 @@ import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.parser.RemoteMangaRepository import org.koitharu.kotatsu.core.util.ext.enqueueWith import org.koitharu.kotatsu.core.util.ext.ifNullOrEmpty +import org.koitharu.kotatsu.parsers.exception.ParseException import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.util.runCatchingCancellable import javax.inject.Inject @@ -28,7 +30,7 @@ class CoverRestorer @Inject constructor( override fun onError(request: ImageRequest, result: ErrorResult) { super.onError(request, result) - if (result.throwable !is HttpException) { + if (!result.throwable.shouldRestore()) { return } request.tags.tag()?.let { @@ -87,4 +89,8 @@ class CoverRestorer @Inject constructor( false } } + + private fun Throwable.shouldRestore(): Boolean { + return this is HttpException || this is HttpStatusException || this is ParseException + } }