Avoid crashes in tracker interceptor errors
This commit is contained in:
parent
0b9d436753
commit
dbb2c523c1
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.anilist
|
|||||||
|
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class AnilistInterceptor(val anilist: Anilist, private var token: String?) : Interceptor {
|
class AnilistInterceptor(val anilist: Anilist, private var token: String?) : Interceptor {
|
||||||
|
|
||||||
@ -28,12 +29,12 @@ class AnilistInterceptor(val anilist: Anilist, private var token: String?) : Int
|
|||||||
// Refresh access token if null or expired.
|
// Refresh access token if null or expired.
|
||||||
if (oauth!!.isExpired()) {
|
if (oauth!!.isExpired()) {
|
||||||
anilist.logout()
|
anilist.logout()
|
||||||
throw Exception("Token expired")
|
throw IOException("Token expired")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Throw on null auth.
|
// Throw on null auth.
|
||||||
if (oauth == null) {
|
if (oauth == null) {
|
||||||
throw Exception("No authentication token")
|
throw IOException("No authentication token")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the authorization header to the original request.
|
// Add the authorization header to the original request.
|
||||||
|
@ -16,15 +16,6 @@ class BangumiInterceptor(val bangumi: Bangumi) : Interceptor {
|
|||||||
*/
|
*/
|
||||||
private var oauth: OAuth? = bangumi.restoreToken()
|
private var oauth: OAuth? = bangumi.restoreToken()
|
||||||
|
|
||||||
fun addToken(token: String, oidFormBody: FormBody): FormBody {
|
|
||||||
val newFormBody = FormBody.Builder()
|
|
||||||
for (i in 0 until oidFormBody.size) {
|
|
||||||
newFormBody.add(oidFormBody.name(i), oidFormBody.value(i))
|
|
||||||
}
|
|
||||||
newFormBody.add("access_token", token)
|
|
||||||
return newFormBody.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun intercept(chain: Interceptor.Chain): Response {
|
override fun intercept(chain: Interceptor.Chain): Response {
|
||||||
val originalRequest = chain.request()
|
val originalRequest = chain.request()
|
||||||
|
|
||||||
@ -65,4 +56,13 @@ class BangumiInterceptor(val bangumi: Bangumi) : Interceptor {
|
|||||||
|
|
||||||
bangumi.saveToken(oauth)
|
bangumi.saveToken(oauth)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun addToken(token: String, oidFormBody: FormBody): FormBody {
|
||||||
|
val newFormBody = FormBody.Builder()
|
||||||
|
for (i in 0 until oidFormBody.size) {
|
||||||
|
newFormBody.add(oidFormBody.name(i), oidFormBody.value(i))
|
||||||
|
}
|
||||||
|
newFormBody.add("access_token", token)
|
||||||
|
return newFormBody.build()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import kotlinx.serialization.json.Json
|
|||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class MyAnimeListInterceptor(private val myanimelist: MyAnimeList, private var token: String?) : Interceptor {
|
class MyAnimeListInterceptor(private val myanimelist: MyAnimeList, private var token: String?) : Interceptor {
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ class MyAnimeListInterceptor(private val myanimelist: MyAnimeList, private var t
|
|||||||
val originalRequest = chain.request()
|
val originalRequest = chain.request()
|
||||||
|
|
||||||
if (token.isNullOrEmpty()) {
|
if (token.isNullOrEmpty()) {
|
||||||
throw Exception("Not authenticated with MyAnimeList")
|
throw IOException("Not authenticated with MyAnimeList")
|
||||||
}
|
}
|
||||||
if (oauth == null) {
|
if (oauth == null) {
|
||||||
oauth = myanimelist.loadOAuth()
|
oauth = myanimelist.loadOAuth()
|
||||||
@ -30,7 +31,7 @@ class MyAnimeListInterceptor(private val myanimelist: MyAnimeList, private var t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (oauth == null) {
|
if (oauth == null) {
|
||||||
throw Exception("No authentication token")
|
throw IOException("No authentication token")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the authorization header to the original request
|
// Add the authorization header to the original request
|
||||||
|
Loading…
Reference in New Issue
Block a user