diff --git a/src/all/comickfun/build.gradle b/src/all/comickfun/build.gradle index a99959019..72f9c69bb 100644 --- a/src/all/comickfun/build.gradle +++ b/src/all/comickfun/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Comick' extClass = '.ComickFactory' - extVersionCode = 43 + extVersionCode = 44 isNsfw = true } diff --git a/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/Comick.kt b/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/Comick.kt index 3265b4c8b..0d9e2702f 100644 --- a/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/Comick.kt +++ b/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/Comick.kt @@ -21,11 +21,13 @@ import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import okhttp3.Headers import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.Interceptor import okhttp3.Request import okhttp3.Response import rx.Observable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import java.util.concurrent.TimeUnit import kotlin.math.min abstract class Comick( @@ -155,9 +157,31 @@ abstract class Comick( } override val client = network.client.newBuilder() - .rateLimit(3, 1) + .addNetworkInterceptor(::errorInterceptor) + .rateLimit(3, 1, TimeUnit.SECONDS) .build() + private fun errorInterceptor(chain: Interceptor.Chain): Response { + val response = chain.proceed(chain.request()) + + if ( + response.isSuccessful || + "application/json" !in response.header("Content-Type").orEmpty() + ) { + return response + } + + val error = try { + response.parseAs() + } catch (_: Exception) { + null + } + + error?.run { + throw Exception("$name error $statusCode: $message") + } ?: throw Exception("HTTP error ${response.code}") + } + /** Popular Manga **/ override fun popularMangaRequest(page: Int): Request { val url = "$apiUrl/v1.0/search?sort=follow&limit=$LIMIT&page=$page&tachiyomi=true" diff --git a/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/Dto.kt b/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/Dto.kt index 7f229f663..f4359c751 100644 --- a/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/Dto.kt +++ b/src/all/comickfun/src/eu/kanade/tachiyomi/extension/all/comickfun/Dto.kt @@ -197,3 +197,9 @@ class ChapterPageData( class Page( val url: String? = null, ) + +@Serializable +class Error( + val statusCode: Int, + val message: String, +)