@@ -1031,45 +1031,8 @@ class UpdateMachine {
1031
1031
if (_disposed) return ;
1032
1032
store.isLoading = true ;
1033
1033
1034
- if (e is ! ApiRequestException ) {
1035
- // Some unexpected error, outside even making the HTTP request.
1036
- // Definitely a bug in our code.
1037
- rethrow ;
1038
- }
1039
-
1040
- bool shouldReportToUser;
1041
- switch (e) {
1042
- case NetworkException (cause: SocketException ()):
1043
- // A [SocketException] is common when the app returns from sleep.
1044
- shouldReportToUser = false ;
1045
-
1046
- case NetworkException ():
1047
- case Server5xxException ():
1048
- shouldReportToUser = true ;
1049
-
1050
- case ServerException (httpStatus: 429 ):
1051
- case ZulipApiException (httpStatus: 429 ):
1052
- case ZulipApiException (code: 'RATE_LIMIT_HIT' ):
1053
- // TODO(#946) handle rate-limit errors more generally, in ApiConnection
1054
- shouldReportToUser = true ;
1055
-
1056
- case ZulipApiException (code: 'BAD_EVENT_QUEUE_ID' ):
1057
- rethrow ;
1058
-
1059
- case ZulipApiException ():
1060
- case MalformedServerResponseException ():
1061
- // Either a 4xx we didn't expect, or a malformed response;
1062
- // in either case, a mismatch of the client's expectations to the
1063
- // server's behavior, and therefore a bug in one or the other.
1064
- // TODO(#1054) handle auth failures specifically
1065
- rethrow ;
1066
- }
1067
-
1068
- assert (debugLog ('Transient error polling event queue for $store : $e \n '
1069
- 'Backing off, then will retry…' ));
1070
- if (shouldReportToUser) {
1071
- _maybeReportToUserTransientError (e);
1072
- }
1034
+ final shouldRetry = _triagePollRequestError (e);
1035
+ if (! shouldRetry) rethrow ;
1073
1036
await (backoffMachine ?? = BackoffMachine ()).wait ();
1074
1037
if (_disposed) return ;
1075
1038
assert (debugLog ('… Backoff wait complete, retrying poll.' ));
@@ -1151,6 +1114,54 @@ class UpdateMachine {
1151
1114
reportErrorToUserBriefly (null );
1152
1115
}
1153
1116
1117
+ /// Sort out an error from the network request in [poll] .
1118
+ ///
1119
+ /// If the request should be retried, this method returns true,
1120
+ /// after reporting the error if appropriate to the user and/or developer.
1121
+ /// Otherwise, this method returns false with no side effects.
1122
+ bool _triagePollRequestError (Object error) {
1123
+ if (error is ! ApiRequestException ) {
1124
+ // Some unexpected error, outside even making the HTTP request.
1125
+ // Definitely a bug in our code.
1126
+ return false ;
1127
+ }
1128
+
1129
+ bool shouldReportToUser;
1130
+ switch (error) {
1131
+ case NetworkException (cause: SocketException ()):
1132
+ // A [SocketException] is common when the app returns from sleep.
1133
+ shouldReportToUser = false ;
1134
+
1135
+ case NetworkException ():
1136
+ case Server5xxException ():
1137
+ shouldReportToUser = true ;
1138
+
1139
+ case ServerException (httpStatus: 429 ):
1140
+ case ZulipApiException (httpStatus: 429 ):
1141
+ case ZulipApiException (code: 'RATE_LIMIT_HIT' ):
1142
+ // TODO(#946) handle rate-limit errors more generally, in ApiConnection
1143
+ shouldReportToUser = true ;
1144
+
1145
+ case ZulipApiException (code: 'BAD_EVENT_QUEUE_ID' ):
1146
+ return false ;
1147
+
1148
+ case ZulipApiException ():
1149
+ case MalformedServerResponseException ():
1150
+ // Either a 4xx we didn't expect, or a malformed response;
1151
+ // in either case, a mismatch of the client's expectations to the
1152
+ // server's behavior, and therefore a bug in one or the other.
1153
+ // TODO(#1054) handle auth failures specifically
1154
+ return false ;
1155
+ }
1156
+
1157
+ assert (debugLog ('Transient error polling event queue for $store : $error \n '
1158
+ 'Backing off, then will retry…' ));
1159
+ if (shouldReportToUser) {
1160
+ _maybeReportToUserTransientError (error);
1161
+ }
1162
+ return true ;
1163
+ }
1164
+
1154
1165
/// Sort out an error in [poll] .
1155
1166
///
1156
1167
/// Reports the error if appropriate to the user and/or developer;
0 commit comments