From 6164fb6b91dd1538f1e36bb928a944e2d5becaed Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 2 May 2023 18:01:09 +0200 Subject: [PATCH] fix(SyncService): handle failing connection gracefully Also fixes the share cypress test. Signed-off-by: Max --- src/services/SyncService.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/SyncService.js b/src/services/SyncService.js index 90a5af4b2d..8be37b6c69 100644 --- a/src/services/SyncService.js +++ b/src/services/SyncService.js @@ -94,17 +94,22 @@ class SyncService { } async open({ fileId, initialSession }) { - this.on('change', ({ sessions }) => { + const onChange = ({ sessions }) => { this.sessions = sessions - }) + } + this.on('change', onChange) const connect = initialSession ? Promise.resolve(new Connection({ data: initialSession }, {})) : this._api.open({ fileId }) .catch(error => this._emitError(error)) - // TODO: Only continue if a connection was made this.connection = await connect + if (!this.connection) { + this.off('change', onChange) + // Error was already emitted in connect + return + } this.backend = new PollingBackend(this, this.connection) this.version = this.connection.docStateVersion this.emit('opened', {