add 400 response login refresh for mal (#476)

* add 400 response update to mal

* clean up imports
This commit is contained in:
Carlos 2020-06-06 16:14:02 -04:00 committed by GitHub
parent 4a30968236
commit 8ce1d94fd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -104,7 +104,7 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) {
}
}
private suspend fun refreshLogin() {
suspend fun refreshLogin() {
val username = getUsername()
val password = getPassword()
logout()

View File

@ -21,7 +21,17 @@ class MyAnimeListInterceptor(private val myanimelist: MyAnimeList) : Interceptor
myanimelist.ensureLoggedIn()
}
val request = chain.request()
return chain.proceed(updateRequest(request))
var response = chain.proceed(updateRequest(request))
if (response.code == 400) {
scope.launch {
myanimelist.refreshLogin()
}
response.close()
response = chain.proceed(updateRequest(request))
}
return response
}
private fun updateRequest(request: Request): Request {