@@ -1044,48 +1044,46 @@ class UpdateMachine {
1044
1044
if (_disposed) return ;
1045
1045
} catch (e) {
1046
1046
if (_disposed) return ;
1047
-
1048
1047
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
+
1050
1055
bool shouldReportToUser;
1051
1056
switch (e) {
1052
- case ZulipApiException (code: 'BAD_EVENT_QUEUE_ID' ):
1053
- rethrow ;
1054
-
1055
1057
case NetworkException (cause: SocketException ()):
1056
1058
// A [SocketException] is common when the app returns from sleep.
1057
- isUnexpected = false ;
1058
1059
shouldReportToUser = false ;
1059
1060
1060
1061
case NetworkException ():
1061
1062
case Server5xxException ():
1062
- isUnexpected = false ;
1063
1063
shouldReportToUser = true ;
1064
1064
1065
1065
case ServerException (httpStatus: 429 ):
1066
1066
case ZulipApiException (httpStatus: 429 ):
1067
1067
case ZulipApiException (code: 'RATE_LIMIT_HIT' ):
1068
1068
// TODO(#946) handle rate-limit errors more generally, in ApiConnection
1069
- isUnexpected = false ;
1070
1069
shouldReportToUser = true ;
1071
1070
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 ;
1075
1081
}
1076
1082
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);
1089
1087
}
1090
1088
await (backoffMachine ?? = BackoffMachine ()).wait ();
1091
1089
if (_disposed) return ;
@@ -1133,7 +1131,7 @@ class UpdateMachine {
1133
1131
} catch (e) {
1134
1132
if (_disposed) return ;
1135
1133
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.
1137
1135
// This means either a lost/expired event queue on the server (which is
1138
1136
// normal after the app is offline for a period like 10 minutes),
1139
1137
// or an unexpected exception representing a bug in our code or the server.
@@ -1171,6 +1169,8 @@ class UpdateMachine {
1171
1169
_reportToUserErrorConnectingToServer (e);
1172
1170
// Similar story to the _EventHandlingException case;
1173
1171
// 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.
1174
1174
isUnexpected = true ;
1175
1175
}
1176
1176
0 commit comments