Add NotFoundException for 404 response

pull/38/head
Koitharu 4 years ago
parent 30071709af
commit 6495ddf277
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -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
}
}

@ -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)
Loading…
Cancel
Save