Skip to content

Commit 48dfd02

Browse files
committed
store [nfc]: Dedupe details of how to report polling failure
1 parent 7e86a9e commit 48dfd02

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

lib/model/store.dart

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -941,10 +941,10 @@ class UpdateMachine {
941941

942942
/// This only reports transient errors after reaching
943943
/// a pre-defined threshold of retries.
944-
void maybeReportTransientError(String? message, {String? details}) {
944+
void maybeReportToUserTransientError(Object error) {
945945
accumulatedTransientFailureCount++;
946946
if (accumulatedTransientFailureCount > transientFailureCountNotifyThreshold) {
947-
reportErrorToUserBriefly(message, details: details);
947+
_reportToUserErrorConnectingToServer(error);
948948
}
949949
}
950950

@@ -974,12 +974,7 @@ class UpdateMachine {
974974
// The error is boring; skip reporting it to the user.
975975
// A [SocketException] is common when the app returns from sleep.
976976
} else {
977-
final localizations = GlobalLocalizations.zulipLocalizations;
978-
final serverUrl = store.connection.realmUrl.origin;
979-
maybeReportTransientError(
980-
localizations.errorConnectingToServerShort,
981-
details: localizations.errorConnectingToServerDetails(
982-
serverUrl, e.toString()));
977+
maybeReportToUserTransientError(e);
983978
}
984979
await (backoffMachine ??= BackoffMachine()).wait();
985980
if (_disposed) return;
@@ -1034,8 +1029,6 @@ class UpdateMachine {
10341029
// Either way, the show must go on. So reload server data from scratch.
10351030

10361031
// First, log what happened.
1037-
final localizations = GlobalLocalizations.zulipLocalizations;
1038-
final serverUrl = store.connection.realmUrl.origin;
10391032
switch (e) {
10401033
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
10411034
assert(debugLog('Lost event queue for $store. Replacing…'));
@@ -1057,10 +1050,7 @@ class UpdateMachine {
10571050
default:
10581051
assert(debugLog('BUG: Unexpected error in event polling: $e\n' // TODO(log)
10591052
'Replacing event queue…'));
1060-
reportErrorToUserBriefly(
1061-
localizations.errorConnectingToServerShort,
1062-
details: localizations.errorConnectingToServerDetails(
1063-
serverUrl, e.toString()));
1053+
_reportToUserErrorConnectingToServer(e);
10641054
// Similar story to the _EventHandlingException case;
10651055
// separate only so that one can print more context.
10661056
// The bug here could be in the server if it's an ApiRequestException,
@@ -1074,6 +1064,15 @@ class UpdateMachine {
10741064
}
10751065
}
10761066

1067+
void _reportToUserErrorConnectingToServer(Object error) {
1068+
final localizations = GlobalLocalizations.zulipLocalizations;
1069+
final serverUrl = store.connection.realmUrl.origin;
1070+
reportErrorToUserBriefly(
1071+
localizations.errorConnectingToServerShort,
1072+
details: localizations.errorConnectingToServerDetails(
1073+
serverUrl, error.toString()));
1074+
}
1075+
10771076
/// Send this client's notification token to the server, now and if it changes.
10781077
///
10791078
/// TODO The returned future isn't especially meaningful (it may or may not

0 commit comments

Comments
 (0)