Handle MAL errors in html

master
Koitharu 2 years ago
parent 6e6c70a770
commit 8efa8bc0d2
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

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

@ -151,7 +151,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())

Loading…
Cancel
Save