Skip to content

Commit c9ebc27

Browse files
committed
store: On non-transient request errors, reload rather than retry
This hopefully gives us a greater chance of getting past whatever the underlying problem is, by resetting more of our state.
1 parent c0d4907 commit c9ebc27

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

lib/model/store.dart

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,48 +1044,46 @@ class UpdateMachine {
10441044
if (_disposed) return;
10451045
} catch (e) {
10461046
if (_disposed) return;
1047-
10481047
store.isLoading = true;
1049-
bool isUnexpected;
1048+
1049+
if (e is! ApiRequestException) {
1050+
// Some unexpected error, outside even making the HTTP request.
1051+
// Definitely a bug in our code.
1052+
rethrow;
1053+
}
1054+
10501055
bool shouldReportToUser;
10511056
switch (e) {
1052-
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
1053-
rethrow;
1054-
10551057
case NetworkException(cause: SocketException()):
10561058
// A [SocketException] is common when the app returns from sleep.
1057-
isUnexpected = false;
10581059
shouldReportToUser = false;
10591060

10601061
case NetworkException():
10611062
case Server5xxException():
1062-
isUnexpected = false;
10631063
shouldReportToUser = true;
10641064

10651065
case ServerException(httpStatus: 429):
10661066
case ZulipApiException(httpStatus: 429):
10671067
case ZulipApiException(code: 'RATE_LIMIT_HIT'):
10681068
// TODO(#946) handle rate-limit errors more generally, in ApiConnection
1069-
isUnexpected = false;
10701069
shouldReportToUser = true;
10711070

1072-
default:
1073-
isUnexpected = true;
1074-
shouldReportToUser = true;
1071+
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
1072+
rethrow;
1073+
1074+
case ZulipApiException():
1075+
case MalformedServerResponseException():
1076+
// Either a 4xx we didn't expect, or a malformed response;
1077+
// in either case, a mismatch of the client's expectations to the
1078+
// server's behavior, and therefore a bug in one or the other.
1079+
// TODO(#1054) handle auth failures specifically
1080+
rethrow;
10751081
}
10761082

1077-
if (isUnexpected) {
1078-
assert(shouldReportToUser);
1079-
assert(debugLog('Error polling event queue for $store: $e\n'
1080-
'Backing off and retrying even though may be hopeless…'));
1081-
// TODO(#186): Handle unrecoverable failures
1082-
_reportToUserErrorConnectingToServer(e);
1083-
} else {
1084-
assert(debugLog('Transient error polling event queue for $store: $e\n'
1085-
'Backing off, then will retry…'));
1086-
if (shouldReportToUser) {
1087-
maybeReportToUserTransientError(e);
1088-
}
1083+
assert(debugLog('Transient error polling event queue for $store: $e\n'
1084+
'Backing off, then will retry…'));
1085+
if (shouldReportToUser) {
1086+
maybeReportToUserTransientError(e);
10891087
}
10901088
await (backoffMachine ??= BackoffMachine()).wait();
10911089
if (_disposed) return;
@@ -1133,7 +1131,7 @@ class UpdateMachine {
11331131
} catch (e) {
11341132
if (_disposed) return;
11351133

1136-
// An error occurred, other than the request errors we retry on.
1134+
// An error occurred, other than the transient request errors we retry on.
11371135
// This means either a lost/expired event queue on the server (which is
11381136
// normal after the app is offline for a period like 10 minutes),
11391137
// or an unexpected exception representing a bug in our code or the server.
@@ -1171,6 +1169,8 @@ class UpdateMachine {
11711169
_reportToUserErrorConnectingToServer(e);
11721170
// Similar story to the _EventHandlingException case;
11731171
// separate only so that that other case can print more context.
1172+
// The bug here could be in the server if it's an ApiRequestException,
1173+
// but our remedy is the same either way.
11741174
isUnexpected = true;
11751175
}
11761176

test/model/store_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,8 @@ void main() {
796796
checkRetry(prepareServer5xxException);
797797
});
798798

799-
test('retries on MalformedServerResponseException', () {
800-
checkRetry(prepareMalformedServerResponseException);
799+
test('reloads on MalformedServerResponseException', () {
800+
checkReload(prepareMalformedServerResponseException);
801801
});
802802

803803
test('retries on rate limit: code RATE_LIMIT_HIT', () {
@@ -812,8 +812,8 @@ void main() {
812812
checkRetry(prepareRateLimitExceptionMalformed);
813813
});
814814

815-
test('retries on generic ZulipApiException', () {
816-
checkRetry(prepareZulipApiExceptionBadRequest);
815+
test('reloads on generic ZulipApiException', () {
816+
checkReload(prepareZulipApiExceptionBadRequest);
817817
});
818818

819819
test('reloads immediately on expired queue', () {

0 commit comments

Comments
 (0)