Skip to content

Commit e95646a

Browse files
committed
wip store [nfc]: pull out _triagePollRequestError
1 parent d06b316 commit e95646a

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.'));
@@ -1044,6 +1022,39 @@ class UpdateMachine {
10441022
reportErrorToUserBriefly(null);
10451023
}
10461024

1025+
/// Sort out an error from the network request in [poll].
1026+
///
1027+
/// If the request should be retried, this method returns true,
1028+
/// after reporting the error if appropriate to the user and/or developer.
1029+
/// Otherwise, this method returns false with no side effects.
1030+
bool _triagePollRequestError(Object error) {
1031+
bool shouldReportToUser;
1032+
switch (error) {
1033+
case NetworkException(cause: SocketException()):
1034+
// A [SocketException] is common when the app returns from sleep.
1035+
shouldReportToUser = false;
1036+
1037+
case NetworkException():
1038+
case Server5xxException():
1039+
shouldReportToUser = true;
1040+
1041+
case ZulipApiException(httpStatus: 429):
1042+
case ZulipApiException(code: 'RATE_LIMIT_HIT'):
1043+
// TODO(#946) handle rate-limit errors more generally, in ApiConnection
1044+
shouldReportToUser = true;
1045+
1046+
default:
1047+
return false;
1048+
}
1049+
1050+
assert(debugLog('Transient error polling event queue for $store: $error\n'
1051+
'Backing off, then will retry…'));
1052+
if (shouldReportToUser) {
1053+
_maybeReportToUserTransientError(error);
1054+
}
1055+
return true;
1056+
}
1057+
10471058
/// Report an error in [poll], if appropriate, to the user and/or developer.
10481059
void _reportPollError(Object error) {
10491060
switch (error) {

0 commit comments

Comments
 (0)