From 6495ddf277889419e592cb81aa615012f14895d0 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Wed, 20 Jul 2022 17:09:37 +0300 Subject: [PATCH] Add NotFoundException for 404 response --- .../org/koitharu/kotatsu/parsers/MangaLoaderContext.kt | 10 +++++----- .../kotatsu/parsers/exception/NotFoundException.kt | 9 +++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/org/koitharu/kotatsu/parsers/exception/NotFoundException.kt diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaLoaderContext.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaLoaderContext.kt index 61e582d16..17316e94e 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaLoaderContext.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaLoaderContext.kt @@ -7,6 +7,7 @@ import org.json.JSONObject import org.jsoup.HttpStatusException import org.koitharu.kotatsu.parsers.config.MangaSourceConfig import org.koitharu.kotatsu.parsers.exception.GraphQLException +import org.koitharu.kotatsu.parsers.exception.NotFoundException import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.parsers.util.await import org.koitharu.kotatsu.parsers.util.parseJson @@ -140,12 +141,10 @@ abstract class MangaLoaderContext { abstract fun getConfig(source: MangaSource): MangaSourceConfig - private fun Response.ensureSuccess() = apply { + private fun Response.ensureSuccess(): Response { val exception: Exception? = when (code) { // Catch some error codes, not all - 404, - in 500..599, - -> HttpStatusException(message, code, request.url.toString()) - + 404 -> NotFoundException(message, request.url.toString()) + in 500..599 -> HttpStatusException(message, code, request.url.toString()) else -> null } if (exception != null) { @@ -156,5 +155,6 @@ abstract class MangaLoaderContext { } throw exception } + return this } } \ No newline at end of file diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/NotFoundException.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/NotFoundException.kt new file mode 100644 index 000000000..b92715771 --- /dev/null +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/NotFoundException.kt @@ -0,0 +1,9 @@ +package org.koitharu.kotatsu.parsers.exception + +import org.jsoup.HttpStatusException +import java.net.HttpURLConnection + +class NotFoundException( + message: String, + url: String, +) : HttpStatusException(message, HttpURLConnection.HTTP_NOT_FOUND, url) \ No newline at end of file