refactor: Add SyncConnectionException to syncloop

This commit is contained in:
Krille 2023-11-27 09:11:57 +01:00
parent f1e0268944
commit 193f404885
No known key found for this signature in database
1 changed files with 8 additions and 4 deletions

View File

@ -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<SyncUpdate?>.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;