Catch sync errors

This commit is contained in:
Christian Pauly 2020-06-01 18:24:41 +00:00
parent b396fc7d71
commit bd00c066c8

View file

@ -647,6 +647,9 @@ class Client {
final StreamController<MatrixException> onError = final StreamController<MatrixException> onError =
StreamController.broadcast(); StreamController.broadcast();
/// Synchronization erros are coming here.
final StreamController<SyncError> onSyncError = StreamController.broadcast();
/// Synchronization erros are coming here. /// Synchronization erros are coming here.
final StreamController<ToDeviceEventDecryptionError> onOlmError = final StreamController<ToDeviceEventDecryptionError> onOlmError =
StreamController.broadcast(); StreamController.broadcast();
@ -1034,8 +1037,11 @@ class Client {
} on MatrixException catch (exception) { } on MatrixException catch (exception) {
onError.add(exception); onError.add(exception);
await Future.delayed(Duration(seconds: syncErrorTimeoutSec), _sync); await Future.delayed(Duration(seconds: syncErrorTimeoutSec), _sync);
} catch (exception) { } catch (e, s) {
print('Error during processing events: ' + exception.toString()); print('Error during processing events: ' + e.toString());
print(s);
onSyncError.add(SyncError(
exception: e is Exception ? e : Exception(e), stackTrace: s));
await Future.delayed(Duration(seconds: syncErrorTimeoutSec), _sync); await Future.delayed(Duration(seconds: syncErrorTimeoutSec), _sync);
} }
} }
@ -1158,7 +1164,7 @@ class Client {
print(s); print(s);
onOlmError.add( onOlmError.add(
ToDeviceEventDecryptionError( ToDeviceEventDecryptionError(
exception: e, exception: e is Exception ? e : Exception(e),
stackTrace: s, stackTrace: s,
toDeviceEvent: toDeviceEvent, toDeviceEvent: toDeviceEvent,
), ),
@ -2191,3 +2197,9 @@ class Client {
return; return;
} }
} }
class SyncError {
Exception exception;
StackTrace stackTrace;
SyncError({this.exception, this.stackTrace});
}