From 193f404885926b0d9d6465018caa5d4e6af5b39f Mon Sep 17 00:00:00 2001 From: Krille Date: Mon, 27 Nov 2023 09:11:57 +0100 Subject: [PATCH] refactor: Add SyncConnectionException to syncloop --- lib/src/client.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 1cfd549c5..6a35b404a 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -19,7 +19,6 @@ import 'dart:async'; import 'dart:convert'; import 'dart:core'; -import 'dart:io'; import 'dart:math'; import 'dart:typed_data'; @@ -1683,7 +1682,7 @@ class Client extends MatrixApi { Logs().d('Running sync while init isn\'t done yet, dropping request'); return; } - Object? syncError; + SyncConnectionException? syncError; await _checkSyncFilter(); timeout ??= const Duration(seconds: 30); final syncRequest = sync( @@ -1692,7 +1691,7 @@ class Client extends MatrixApi { timeout: timeout.inMilliseconds, setPresence: syncPresence, ).then((v) => Future.value(v)).catchError((e) { - syncError = e; + syncError = SyncConnectionException(e); return null; }); _currentSyncId = syncRequest.hashCode; @@ -1753,7 +1752,7 @@ class Client extends MatrixApi { Logs().w('The user has been logged out!'); await clear(); } - } on IOException catch (e, s) { + } on SyncConnectionException catch (e, s) { Logs().w('Syncloop failed: Client has not connection to the server'); onSyncStatus.add(SyncStatusUpdate(SyncStatus.error, error: SdkError(exception: e, stackTrace: s))); @@ -3122,6 +3121,11 @@ class SdkError { SdkError({this.exception, this.stackTrace}); } +class SyncConnectionException implements Exception { + final Object originalException; + SyncConnectionException(this.originalException); +} + class SyncStatusUpdate { final SyncStatus status; final SdkError? error;