Skip to content

Commit 9c1c31c

Browse files
committed
wip store [nfc]: pull out _triagePollRequestError
1 parent 5d22587 commit 9c1c31c

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

lib/model/store.dart

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

951951
store.isLoading = true;
952-
bool shouldReportToUser;
953-
switch (e) {
954-
case NetworkException(cause: SocketException()):
955-
// A [SocketException] is common when the app returns from sleep.
956-
shouldReportToUser = false;
957-
958-
case NetworkException():
959-
case Server5xxException():
960-
shouldReportToUser = true;
961-
962-
case ZulipApiException(httpStatus: 429):
963-
case ZulipApiException(code: 'RATE_LIMIT_HIT'):
964-
// TODO(#946) handle rate-limit errors more generally, in ApiConnection
965-
shouldReportToUser = true;
966-
967-
default:
968-
rethrow;
969-
}
970-
971-
assert(debugLog('Transient error polling event queue for $store: $e\n'
972-
'Backing off, then will retry…'));
973-
if (shouldReportToUser) {
974-
_maybeReportToUserTransientError(e);
975-
}
952+
final shouldRetry = _triagePollRequestError(e);
953+
if (!shouldRetry) rethrow;
976954
await (backoffMachine ??= BackoffMachine()).wait();
977955
if (_disposed) return;
978956
assert(debugLog('… Backoff wait complete, retrying poll.'));
@@ -1043,6 +1021,39 @@ class UpdateMachine {
10431021
reportErrorToUserBriefly(null);
10441022
}
10451023

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) {
1030+
bool shouldReportToUser;
1031+
switch (error) {
1032+
case NetworkException(cause: SocketException()):
1033+
// A [SocketException] is common when the app returns from sleep.
1034+
shouldReportToUser = false;
1035+
1036+
case NetworkException():
1037+
case Server5xxException():
1038+
shouldReportToUser = true;
1039+
1040+
case ZulipApiException(httpStatus: 429):
1041+
case ZulipApiException(code: 'RATE_LIMIT_HIT'):
1042+
// TODO(#946) handle rate-limit errors more generally, in ApiConnection
1043+
shouldReportToUser = true;
1044+
1045+
default:
1046+
return false;
1047+
}
1048+
1049+
assert(debugLog('Transient error polling event queue for $store: $error\n'
1050+
'Backing off, then will retry…'));
1051+
if (shouldReportToUser) {
1052+
_maybeReportToUserTransientError(error);
1053+
}
1054+
return true;
1055+
}
1056+
10461057
/// Report an error in [poll], if appropriate, to the user and/or developer.
10471058
void _reportPollError(Object error) {
10481059
switch (error) {

0 commit comments

Comments
 (0)