From 7ec822503a50700153840d34095ac994415bcac2 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 18 Sep 2022 16:24:26 -0400 Subject: [PATCH] Catch error properly when app update check fails (fixes #8019) --- .../tachiyomi/data/updater/AppUpdateService.kt | 8 ++++---- .../eu/kanade/tachiyomi/ui/more/AboutController.kt | 12 ++++++------ .../eu/kanade/tachiyomi/network/OkHttpExtensions.kt | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt index dc4fff33c..7cd6abd34 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt @@ -133,10 +133,10 @@ class AppUpdateService : Service() { throw Exception("Unsuccessful response") } notifier.promptInstall(apkFile.getUriCompat(this)) - } catch (error: Exception) { - logcat(LogPriority.ERROR, error) - if (error is CancellationException || - (error is StreamResetException && error.errorCode == ErrorCode.CANCEL) + } catch (e: Exception) { + logcat(LogPriority.ERROR, e) + if (e is CancellationException || + (e is StreamResetException && e.errorCode == ErrorCode.CANCEL) ) { notifier.cancel() } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 71f37ad54..1d3245186 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -45,9 +45,9 @@ class AboutController : BasicFullComposeController() { activity!!.toast(R.string.update_check_look_for_updates) viewScope.launchIO { - val result = updateChecker.checkForUpdate(activity!!, isUserPrompt = true) - withUIContext { - try { + try { + val result = updateChecker.checkForUpdate(activity!!, isUserPrompt = true) + withUIContext { when (result) { is AppUpdateResult.NewUpdate -> { NewUpdateDialogController(result).showDialog(router) @@ -57,10 +57,10 @@ class AboutController : BasicFullComposeController() { } else -> {} } - } catch (error: Exception) { - activity?.toast(error.message) - logcat(LogPriority.ERROR, error) } + } catch (e: Exception) { + withUIContext { activity?.toast(e.message) } + logcat(LogPriority.ERROR, e) } } } diff --git a/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt b/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt index 0b21f28ed..ad4845327 100644 --- a/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt +++ b/core/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt @@ -37,9 +37,9 @@ fun Call.asObservable(): Observable { subscriber.onNext(response) subscriber.onCompleted() } - } catch (error: Exception) { + } catch (e: Exception) { if (!subscriber.isUnsubscribed) { - subscriber.onError(error) + subscriber.onError(e) } } }