Skip to content

Commit f09cae5

Browse files
committed
wip better, two separate functions
1 parent 76f3486 commit f09cae5

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

lib/model/store.dart

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -949,19 +949,8 @@ class UpdateMachine {
949949
if (_disposed) return;
950950

951951
store.isLoading = true;
952-
switch (e) {
953-
case NetworkException():
954-
case Server5xxException():
955-
case ZulipApiException(httpStatus: 429):
956-
case ZulipApiException(code: 'RATE_LIMIT_HIT'):
957-
// TODO(#946) handle rate-limit errors more generally, in ApiConnection
958-
break;
959-
960-
default:
961-
rethrow;
962-
}
963-
964-
_reportPollError(e, transient: true);
952+
final shouldRetry = _triagePollRequestError(e);
953+
if (!shouldRetry) rethrow;
965954
await (backoffMachine ??= BackoffMachine()).wait();
966955
if (_disposed) return;
967956
assert(debugLog('… Backoff wait complete, retrying poll.'));
@@ -1009,7 +998,7 @@ class UpdateMachine {
1009998
// or an unexpected exception representing a bug in our code or the server.
1010999
// Either way, the show must go on. So reload server data from scratch.
10111000

1012-
_reportPollError(e, transient: false);
1001+
_reportPollError(e);
10131002

10141003
// This disposes the store, which disposes this update machine.
10151004
await store._globalStore._reloadPerAccount(store.accountId);
@@ -1032,15 +1021,19 @@ class UpdateMachine {
10321021
reportErrorToUserBriefly(null);
10331022
}
10341023

1035-
/// Report an error in [poll] to the user if appropriate,
1036-
/// and to the developer console in debug builds.
1037-
void _reportPollError(Object error, {required bool transient}) {
1024+
/// Sort out an error from the network request in [poll].
1025+
///
1026+
/// If the request should be retried, this method returns true,
1027+
/// after reporting the error if appropriate to the user and/or developer.
1028+
/// Otherwise, this method returns false with no side effects.
1029+
bool _triagePollRequestError(Object error) {
10381030
switch (error) {
10391031
case NetworkException(cause: SocketException()):
10401032
assert(debugLog('Transient error polling event queue for $store: $error\n'
10411033
'Backing off, then will retry…'));
10421034
// A [SocketException] is common when the app returns from sleep.
10431035
// Don't bother the user about it.
1036+
return true;
10441037

10451038
case NetworkException():
10461039
case Server5xxException():
@@ -1050,7 +1043,17 @@ class UpdateMachine {
10501043
assert(debugLog('Transient error polling event queue for $store: $error\n'
10511044
'Backing off, then will retry…'));
10521045
_maybeReportToUserTransientError(error);
1046+
return true;
1047+
1048+
default:
1049+
return false;
1050+
}
1051+
}
10531052

1053+
/// Report an error in [poll] to the user if appropriate,
1054+
/// and to the developer console in debug builds.
1055+
void _reportPollError(Object error) {
1056+
switch (error) {
10541057
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
10551058
assert(debugLog('Lost event queue for $store. Replacing…'));
10561059
// The old event queue is gone, so we need a new one. This is normal.

0 commit comments

Comments
 (0)