diff options
Diffstat (limited to 'src/services/SyncService.js')
-rw-r--r-- | src/services/SyncService.js | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/src/services/SyncService.js b/src/services/SyncService.js index 651a5ee2b..34d10b15e 100644 --- a/src/services/SyncService.js +++ b/src/services/SyncService.js @@ -97,37 +97,20 @@ class SyncService { } async open({ fileId, filePath, initialSession }) { - let connectionData = null - if (typeof initialSession === 'undefined') { - try { - const response = await this._openDocument({ fileId, filePath }) - connectionData = response.data - } catch (error) { - if (!error.response || error.code === 'ECONNABORTED') { - this.emit('error', ERROR_TYPE.CONNECTION_FAILED, {}) - } else { - this.emit('error', ERROR_TYPE.LOAD_ERROR, error.response.status) - } - throw error - } - } else { - connectionData = initialSession - } - + const connectionData = initialSession + || await this._openDocument({ fileId, filePath }) this.document = connectionData.document this.document.readOnly = connectionData.readOnly this.session = connectionData.session - this.emit('opened', { document: this.document, session: this.session, }) - return this._fetchDocument().then(({ data }) => { - this.emit('loaded', { - document: this.document, - session: this.session, - documentSource: '' + data, - }) + const fetched = await this._fetchDocument() + this.emit('loaded', { + document: this.document, + session: this.session, + documentSource: '' + fetched.data, }) } @@ -143,6 +126,14 @@ class SyncService { guestName: this.options.guestName, forceRecreate: this.options.forceRecreate, }) + .then(response => response.data, error => { + if (!error.response || error.code === 'ECONNABORTED') { + this.emit('error', ERROR_TYPE.CONNECTION_FAILED, {}) + } else { + this.emit('error', ERROR_TYPE.LOAD_ERROR, error.response.status) + } + throw error + }) } _fetchDocument() { |