From 2a5102a4572f5250c60e2e97cc5ff41cb7d65e17 Mon Sep 17 00:00:00 2001 From: Andreas Date: Fri, 22 Jan 2021 00:05:22 +0100 Subject: [PATCH] Fix Kitsu toasting "Logged in" when there is an error (#4329) --- .../eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt | 12 ++++-------- .../tachiyomi/ui/setting/track/TrackLoginDialog.kt | 1 + 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt index 36f0db94a..7cd4473df 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt @@ -101,14 +101,10 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) { } override suspend fun login(username: String, password: String) { - try { - val token = api.login(username, password) - interceptor.newAuth(token) - val userId = api.getCurrentUser() - saveCredentials(username, userId) - } catch (e: Throwable) { - logout() - } + val token = api.login(username, password) + interceptor.newAuth(token) + val userId = api.getCurrentUser() + saveCredentials(username, userId) } override fun logout() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt index aef7cbca2..d59b3510d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/track/TrackLoginDialog.kt @@ -48,6 +48,7 @@ class TrackLoginDialog( dialog?.dismiss() withUIContext { view?.context?.toast(R.string.login_success) } } catch (e: Throwable) { + service.logout() binding?.login?.progress = -1 binding?.login?.setText(R.string.unknown_error) withUIContext { e.message?.let { view?.context?.toast(it) } }