diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt index 65dac87a2..cd26b51ee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt @@ -44,7 +44,7 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI .add("code_verifier", codeVerifier) .add("grant_type", "authorization_code") .build() - client.newCall(POST("$baseOAuthUrl/token", body = formBody)).await(assertSuccess = true).use { + client.newCall(POST("$baseOAuthUrl/token", body = formBody)).await().use { val responseBody = it.body?.string().orEmpty() json.decodeFromString(responseBody) } @@ -57,7 +57,7 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI .url("$baseApiUrl/users/@me") .get() .build() - authClient.newCall(request).await(assertSuccess = true).use { + authClient.newCall(request).await().use { val responseBody = it.body?.string().orEmpty() val response = json.decodeFromString(responseBody) response["name"]!!.jsonPrimitive.content @@ -70,7 +70,7 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI val url = "$baseApiUrl/manga".toUri().buildUpon() .appendQueryParameter("q", query) .build() - authClient.newCall(GET(url.toString())).await(assertSuccess = true).use { + authClient.newCall(GET(url.toString())).await().use { val responseBody = it.body?.string().orEmpty() val response = json.decodeFromString(responseBody) response["data"]!!.jsonArray @@ -91,7 +91,7 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI .appendPath(id.toString()) .appendQueryParameter("fields", "id,title,synopsis,num_chapters,main_picture,status,media_type,start_date") .build() - authClient.newCall(GET(url.toString())).await(assertSuccess = true).use { + authClient.newCall(GET(url.toString())).await().use { val responseBody = it.body?.string().orEmpty() val response = json.decodeFromString(responseBody) val obj = response.jsonObject @@ -124,7 +124,7 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI .url(mangaUrl(track.media_id).toString()) .put(formBody) .build() - authClient.newCall(request).await(assertSuccess = true).use { + authClient.newCall(request).await().use { parseMangaItem(it, track) } } @@ -140,7 +140,7 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI .url(mangaUrl(track.media_id).toString()) .put(formBody) .build() - authClient.newCall(request).await(assertSuccess = true).use { + authClient.newCall(request).await().use { parseMangaItem(it, track) } } @@ -158,7 +158,7 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI .url(mangaUrl(track.media_id).toString()) .put(formBody) .build() - authClient.newCall(request).await(assertSuccess = true).use { + authClient.newCall(request).await().use { parseMangaItem(it, track) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt index 5e8b660d3..2e059a981 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt @@ -52,12 +52,12 @@ fun Call.asObservable(): Observable { } // Based on https://github.com/gildor/kotlin-coroutines-okhttp -suspend fun Call.await(assertSuccess: Boolean = false): Response { +suspend fun Call.await(): Response { return suspendCancellableCoroutine { continuation -> enqueue( object : Callback { override fun onResponse(call: Call, response: Response) { - if (assertSuccess && !response.isSuccessful) { + if (!response.isSuccessful) { continuation.resumeWithException(Exception("HTTP error ${response.code}")) return }