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