Skip to content

Commit 00c5107

Browse files
committed
store [nfc]: Dedupe details of how to report polling failure
1 parent f7dce96 commit 00c5107

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
@@ -930,10 +930,10 @@ class UpdateMachine {
930930

931931
/// This only reports transient errors after reaching
932932
/// a pre-defined threshold of retries.
933-
void maybeReportTransientError(String? message, {String? details}) {
933+
void maybeReportToUserTransientError(Object error) {
934934
accumulatedTransientFailureCount++;
935935
if (accumulatedTransientFailureCount > transientFailureCountNotifyThreshold) {
936-
reportErrorToUserBriefly(message, details: details);
936+
_reportToUserErrorConnectingToServer(error);
937937
}
938938
}
939939

@@ -963,12 +963,7 @@ class UpdateMachine {
963963
// The error is boring; skip reporting it to the user.
964964
// A [SocketException] is common when the app returns from sleep.
965965
} else {
966-
final localizations = GlobalLocalizations.zulipLocalizations;
967-
final serverUrl = store.connection.realmUrl.origin;
968-
maybeReportTransientError(
969-
localizations.errorConnectingToServerShort,
970-
details: localizations.errorConnectingToServerDetails(
971-
serverUrl, e.toString()));
966+
maybeReportToUserTransientError(e);
972967
}
973968
await (backoffMachine ??= BackoffMachine()).wait();
974969
if (_disposed) return;
@@ -1023,8 +1018,6 @@ class UpdateMachine {
10231018
// Either way, the show must go on. So reload server data from scratch.
10241019

10251020
// First, log what happened.
1026-
final localizations = GlobalLocalizations.zulipLocalizations;
1027-
final serverUrl = store.connection.realmUrl.origin;
10281021
switch (e) {
10291022
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
10301023
assert(debugLog('Lost event queue for $store. Replacing…'));
@@ -1046,10 +1039,7 @@ class UpdateMachine {
10461039
default:
10471040
assert(debugLog('BUG: Unexpected error in event polling: $e\n' // TODO(log)
10481041
'Replacing event queue…'));
1049-
reportErrorToUserBriefly(
1050-
localizations.errorConnectingToServerShort,
1051-
details: localizations.errorConnectingToServerDetails(
1052-
serverUrl, e.toString()));
1042+
_reportToUserErrorConnectingToServer(e);
10531043
// Similar story to the _EventHandlingException case;
10541044
// separate only so that one can print more context.
10551045
// The bug here could be in the server if it's an ApiRequestException,
@@ -1063,6 +1053,15 @@ class UpdateMachine {
10631053
}
10641054
}
10651055

1056+
void _reportToUserErrorConnectingToServer(Object error) {
1057+
final localizations = GlobalLocalizations.zulipLocalizations;
1058+
final serverUrl = store.connection.realmUrl.origin;
1059+
reportErrorToUserBriefly(
1060+
localizations.errorConnectingToServerShort,
1061+
details: localizations.errorConnectingToServerDetails(
1062+
serverUrl, error.toString()));
1063+
}
1064+
10661065
/// Send this client's notification token to the server, now and if it changes.
10671066
///
10681067
/// TODO The returned future isn't especially meaningful (it may or may not

0 commit comments

Comments
 (0)