Merge branch 'krille/catch-all-sync-errors' into 'master'

Catch all sync errors

See merge request famedly/famedlysdk!374
This commit is contained in:
Christian Pauly 2020-06-30 14:47:40 +00:00
commit ad098aa246

View file

@ -669,18 +669,25 @@ class Client {
} }
Future<SyncUpdate> _syncRequest; Future<SyncUpdate> _syncRequest;
Exception _lastSyncError;
Future<void> _sync() async { Future<void> _sync() async {
if (isLogged() == false || _disposed) return; if (isLogged() == false || _disposed) return;
try { try {
_syncRequest = api.sync( _syncRequest = api
.sync(
filter: syncFilters, filter: syncFilters,
since: prevBatch, since: prevBatch,
timeout: prevBatch != null ? 30000 : null, timeout: prevBatch != null ? 30000 : null,
); )
.catchError((e) {
_lastSyncError = e;
return null;
});
if (_disposed) return; if (_disposed) return;
final hash = _syncRequest.hashCode; final hash = _syncRequest.hashCode;
final syncResp = await _syncRequest; final syncResp = await _syncRequest;
if (syncResp == null) throw _lastSyncError;
if (hash != _syncRequest.hashCode) return; if (hash != _syncRequest.hashCode) return;
if (database != null) { if (database != null) {
await database.transaction(() async { await database.transaction(() async {