Handle MAL errors in html
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user