Skip to content

Commit 1bf4422

Browse files
committed
store [nfc]: Dedupe details of how to report polling failure
1 parent 0cf73b9 commit 1bf4422

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

lib/model/store.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,10 +1008,10 @@ class UpdateMachine {
10081008

10091009
/// This only reports transient errors after reaching
10101010
/// a pre-defined threshold of retries.
1011-
void maybeReportTransientError(String? message, {String? details}) {
1011+
void maybeReportToUserTransientError(Object error) {
10121012
accumulatedTransientFailureCount++;
10131013
if (accumulatedTransientFailureCount > transientFailureCountNotifyThreshold) {
1014-
reportErrorToUserBriefly(message, details: details);
1014+
_reportToUserErrorConnectingToServer(error);
10151015
}
10161016
}
10171017

@@ -1034,8 +1034,6 @@ class UpdateMachine {
10341034
if (_disposed) return;
10351035

10361036
store.isLoading = true;
1037-
final localizations = GlobalLocalizations.zulipLocalizations;
1038-
final serverUrl = store.realmUrl.toString();
10391037
switch (e) {
10401038
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
10411039
assert(debugLog('Lost event queue for $store. Replacing…'));
@@ -1047,10 +1045,7 @@ class UpdateMachine {
10471045
case Server5xxException():
10481046
assert(debugLog('Transient error polling event queue for $store: $e\n'
10491047
'Backing off, then will retry…'));
1050-
maybeReportTransientError(
1051-
localizations.errorConnectingToServerShort,
1052-
details: localizations.errorConnectingToServerDetails(
1053-
serverUrl, e.toString()));
1048+
maybeReportToUserTransientError(e);
10541049
await (backoffMachine ??= BackoffMachine()).wait();
10551050
if (_disposed) return;
10561051
assert(debugLog('… Backoff wait complete, retrying poll.'));
@@ -1062,10 +1057,7 @@ class UpdateMachine {
10621057
if (e.cause is! SocketException) {
10631058
// Heuristic check to only report interesting errors to the user.
10641059
// A [SocketException] is common when the app returns from sleep.
1065-
maybeReportTransientError(
1066-
localizations.errorConnectingToServerShort,
1067-
details: localizations.errorConnectingToServerDetails(
1068-
serverUrl, e.toString()));
1060+
maybeReportToUserTransientError(e);
10691061
}
10701062
await (backoffMachine ??= BackoffMachine()).wait();
10711063
if (_disposed) return;
@@ -1076,10 +1068,7 @@ class UpdateMachine {
10761068
assert(debugLog('Error polling event queue for $store: $e\n'
10771069
'Backing off and retrying even though may be hopeless…'));
10781070
// TODO(#186): Handle unrecoverable failures
1079-
reportErrorToUserBriefly(
1080-
localizations.errorConnectingToServerShort,
1081-
details: localizations.errorConnectingToServerDetails(
1082-
serverUrl, e.toString()));
1071+
_reportToUserErrorConnectingToServer(e);
10831072
await (backoffMachine ??= BackoffMachine()).wait();
10841073
if (_disposed) return;
10851074
assert(debugLog('… Backoff wait complete, retrying poll.'));
@@ -1119,6 +1108,14 @@ class UpdateMachine {
11191108
}
11201109
}
11211110

1111+
void _reportToUserErrorConnectingToServer(Object error) {
1112+
final localizations = GlobalLocalizations.zulipLocalizations;
1113+
reportErrorToUserBriefly(
1114+
localizations.errorConnectingToServerShort,
1115+
details: localizations.errorConnectingToServerDetails(
1116+
store.realmUrl.toString(), error.toString()));
1117+
}
1118+
11221119
/// Send this client's notification token to the server, now and if it changes.
11231120
///
11241121
/// TODO The returned future isn't especially meaningful (it may or may not

0 commit comments

Comments
 (0)