mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Avoid crashes in tracker interceptor errors
This commit is contained in:
		| @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.anilist | ||||
|  | ||||
| import okhttp3.Interceptor | ||||
| import okhttp3.Response | ||||
| import java.io.IOException | ||||
|  | ||||
| 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. | ||||
|         if (oauth!!.isExpired()) { | ||||
|             anilist.logout() | ||||
|             throw Exception("Token expired") | ||||
|             throw IOException("Token expired") | ||||
|         } | ||||
|  | ||||
|         // Throw on null auth. | ||||
|         if (oauth == null) { | ||||
|             throw Exception("No authentication token") | ||||
|             throw IOException("No authentication token") | ||||
|         } | ||||
|  | ||||
|         // Add the authorization header to the original request. | ||||
|   | ||||
| @@ -16,15 +16,6 @@ class BangumiInterceptor(val bangumi: Bangumi) : Interceptor { | ||||
|      */ | ||||
|     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 { | ||||
|         val originalRequest = chain.request() | ||||
|  | ||||
| @@ -65,4 +56,13 @@ class BangumiInterceptor(val bangumi: Bangumi) : Interceptor { | ||||
|  | ||||
|         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.Response | ||||
| import uy.kohesive.injekt.injectLazy | ||||
| import java.io.IOException | ||||
|  | ||||
| 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() | ||||
|  | ||||
|         if (token.isNullOrEmpty()) { | ||||
|             throw Exception("Not authenticated with MyAnimeList") | ||||
|             throw IOException("Not authenticated with MyAnimeList") | ||||
|         } | ||||
|         if (oauth == null) { | ||||
|             oauth = myanimelist.loadOAuth() | ||||
| @@ -30,7 +31,7 @@ class MyAnimeListInterceptor(private val myanimelist: MyAnimeList, private var t | ||||
|             } | ||||
|         } | ||||
|         if (oauth == null) { | ||||
|             throw Exception("No authentication token") | ||||
|             throw IOException("No authentication token") | ||||
|         } | ||||
|  | ||||
|         // Add the authorization header to the original request | ||||
|   | ||||
		Reference in New Issue
	
	Block a user