Skip to content

Commit 04dcda4

Browse files
committed
store: Reoprt non-transient polling errors.
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 99b48a4 commit 04dcda4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/model/store.dart

+1
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ class UpdateMachine {
801801
assert(debugLog('Error polling event queue for $store: $e\n'
802802
'Backing off and retrying even though may be hopeless…'));
803803
// TODO tell user on non-transient error in polling
804+
reportErrorToUserInDialog('Error loading server data. Will retry: $e');
804805
await (backoffMachine ??= BackoffMachine()).wait();
805806
assert(debugLog('… Backoff wait complete, retrying poll.'));
806807
continue;

test/model/store_test.dart

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:zulip/api/model/events.dart';
88
import 'package:zulip/api/model/model.dart';
99
import 'package:zulip/api/route/events.dart';
1010
import 'package:zulip/api/route/messages.dart';
11+
import 'package:zulip/log.dart';
1112
import 'package:zulip/model/store.dart';
1213
import 'package:zulip/notifications/receive.dart';
1314

@@ -427,7 +428,9 @@ void main() {
427428
check(store.userSettings!.twentyFourHourTime).isTrue();
428429
}));
429430

430-
void checkRetry(String description, void Function() prepareError) {
431+
void checkRetry(String description, void Function() prepareError, {
432+
String? errorMessage,
433+
}) {
431434
test(description, () {
432435
awaitFakeAsync((async) async {
433436
await prepareStore(lastEventId: 1);
@@ -438,7 +441,13 @@ void main() {
438441
// Make the request, inducing an error in it.
439442
prepareError();
440443
updateMachine.debugAdvanceLoop();
444+
check(debugLastReportedError).isNull();
441445
async.elapse(Duration.zero);
446+
if (errorMessage == null) {
447+
check(takeLastReportedError()).isNull();
448+
} else {
449+
check(takeLastReportedError()).isNotNull().contains(errorMessage);
450+
}
442451
checkLastRequest(lastEventId: 1);
443452
check(store).isLoading.isTrue();
444453

@@ -470,10 +479,12 @@ void main() {
470479

471480
checkRetry('retries on ZulipApiException',
472481
() => connection.prepare(httpStatus: 400, json: {
473-
'result': 'error', 'code': 'BAD_REQUEST', 'msg': 'Bad request'}));
482+
'result': 'error', 'code': 'BAD_REQUEST', 'msg': 'Bad request'}),
483+
errorMessage: 'Error loading server data. Will retry');
474484

475485
checkRetry('retries on MalformedServerResponseException',
476-
() => connection.prepare(httpStatus: 200, body: 'nonsense'));
486+
() => connection.prepare(httpStatus: 200, body: 'nonsense'),
487+
errorMessage: 'Error loading server data. Will retry');
477488
});
478489
});
479490

0 commit comments

Comments
 (0)