From 2f327911177c1a424cf3498ff0f2e0a216dcee73 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 29 Jun 2020 14:09:40 +0200 Subject: [PATCH] Catch all sync errors --- lib/src/client.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 23f2687..2c1688d 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -669,18 +669,25 @@ class Client { } Future _syncRequest; + Exception _lastSyncError; Future _sync() async { if (isLogged() == false || _disposed) return; try { - _syncRequest = api.sync( + _syncRequest = api + .sync( filter: syncFilters, since: prevBatch, timeout: prevBatch != null ? 30000 : null, - ); + ) + .catchError((e) { + _lastSyncError = e; + return null; + }); if (_disposed) return; final hash = _syncRequest.hashCode; final syncResp = await _syncRequest; + if (syncResp == null) throw _lastSyncError; if (hash != _syncRequest.hashCode) return; if (database != null) { await database.transaction(() async {