Handle MAL errors in html

This commit is contained in:
Koitharu
2024-02-01 10:31:23 +02:00
parent 54ef02ad88
commit d24754f2a0
2 changed files with 11 additions and 2 deletions

View File

@@ -2,10 +2,14 @@ package org.koitharu.kotatsu.scrobbling.mal.data
import okhttp3.Interceptor
import okhttp3.Response
import okio.IOException
import org.koitharu.kotatsu.core.network.CommonHeaders
import org.koitharu.kotatsu.parsers.util.mimeType
import org.koitharu.kotatsu.parsers.util.parseHtml
import org.koitharu.kotatsu.scrobbling.common.data.ScrobblerStorage
private const val JSON = "application/json"
private const val HTML = "text/html"
class MALInterceptor(private val storage: ScrobblerStorage) : Interceptor {
@@ -19,7 +23,11 @@ class MALInterceptor(private val storage: ScrobblerStorage) : Interceptor {
request.header(CommonHeaders.AUTHORIZATION, "Bearer $it")
}
}
return chain.proceed(request.build())
val response = chain.proceed(request.build())
if (response.mimeType == HTML) {
throw IOException(response.parseHtml().title())
}
return response
}
}

View File

@@ -150,7 +150,8 @@ class MALRepository @Inject constructor(
override suspend fun updateRate(rateId: Int, mangaId: Long, rating: Float, status: String?, comment: String?) {
val body = FormBody.Builder()
.add("status", status.toString())
.add("score", rating.toString())
.add("score", rating.toInt().toString())
.add("comments", comment.orEmpty())
val url = BASE_API_URL.toHttpUrl().newBuilder()
.addPathSegment("manga")
.addPathSegment(rateId.toString())