From b87a038ca1641539123823ba9b05cd158f811275 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Fri, 8 Nov 2024 20:37:07 -0800 Subject: [PATCH] store [nfc]: Manage isLoading alongside error logic in poll This is basically a form of error reporting. --- lib/model/store.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/model/store.dart b/lib/model/store.dart index 49164dfb77..dc1b656d4d 100644 --- a/lib/model/store.dart +++ b/lib/model/store.dart @@ -1029,8 +1029,6 @@ class UpdateMachine { if (_disposed) return; } catch (e) { if (_disposed) return; - store.isLoading = true; - final shouldRetry = _triagePollRequestError(e); if (!shouldRetry) rethrow; await (backoffMachine ??= BackoffMachine()).wait(); @@ -1056,7 +1054,6 @@ class UpdateMachine { // and failures, the successes themselves should space out the requests. backoffMachine = null; - store.isLoading = false; _clearReportingErrorsToUser(); final events = result.events; @@ -1083,7 +1080,6 @@ class UpdateMachine { // or an unexpected exception representing a bug in our code or the server. // Either way, the show must go on. So reload server data from scratch. - store.isLoading = true; final isUnexpected = _triagePollError(e); if (isUnexpected) { @@ -1110,6 +1106,7 @@ class UpdateMachine { int _accumulatedTransientFailureCount = 0; void _clearReportingErrorsToUser() { + store.isLoading = false; _accumulatedTransientFailureCount = 0; reportErrorToUserBriefly(null); } @@ -1120,6 +1117,8 @@ class UpdateMachine { /// after reporting the error if appropriate to the user and/or developer. /// Otherwise, this method returns false with no side effects. bool _triagePollRequestError(Object error) { + store.isLoading = true; + if (error is! ApiRequestException) { // Some unexpected error, outside even making the HTTP request. // Definitely a bug in our code. @@ -1167,6 +1166,8 @@ class UpdateMachine { /// Reports the error if appropriate to the user and/or developer; /// then returns true just if the error was unexpected. bool _triagePollError(Object error) { + store.isLoading = true; + bool isUnexpected; switch (error) { case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):