diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-07-09 11:55:46 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-07-10 17:11:40 +0300 |
commit | e9e09b82b908690991cd9c60e4baedd8833c83f5 (patch) | |
tree | 281ef8ea4a2a03624c7f9a1f5638c54b36e25498 /src | |
parent | eb155ec1e94f33574d990fb33459b91bce311e18 (diff) |
Reconnect after session has timed out
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/EditorFactory.js | 7 | ||||
-rw-r--r-- | src/components/EditorWrapper.vue | 21 | ||||
-rw-r--r-- | src/services/PollingBackend.js | 11 | ||||
-rw-r--r-- | src/services/SyncService.js | 6 |
4 files changed, 39 insertions, 6 deletions
diff --git a/src/EditorFactory.js b/src/EditorFactory.js index e0cbd3206..32fbf12be 100644 --- a/src/EditorFactory.js +++ b/src/EditorFactory.js @@ -101,7 +101,7 @@ const createEditor = ({ content, onUpdate, extensions, enableRichEditing, langua const markdownit = MarkdownIt('commonmark', { html: false, breaks: false }) .enable('strikethrough') -const SerializeException = (message) => { +const SerializeException = function(message) { this.message = message } const createMarkdownSerializer = (_nodes, _marks) => { @@ -135,7 +135,10 @@ const createMarkdownSerializer = (_nodes, _marks) => { const serializePlainText = (tiptap) => { const doc = tiptap.getJSON() - if (doc.content.length !== 1 || doc.content[0].content.length !== 1) { + if (doc.content.length !== 1 || typeof doc.content[0].content === 'undefined' || doc.content[0].content.length !== 1) { + if (doc.content[0].type === 'code_block' && typeof doc.content[0].content === 'undefined') { + return '' + } throw new SerializeException('Failed to serialize document to plain text') } const codeBlock = doc.content[0].content[0] diff --git a/src/components/EditorWrapper.vue b/src/components/EditorWrapper.vue index 0f606378c..50046e6db 100644 --- a/src/components/EditorWrapper.vue +++ b/src/components/EditorWrapper.vue @@ -305,14 +305,24 @@ export default { this.document = document }) .on('error', (error, data) => { + this.tiptap.setOptions({ editable: false }) if (error === ERROR_TYPE.SAVE_COLLISSION && (!this.syncError || this.syncError.type !== ERROR_TYPE.SAVE_COLLISSION)) { this.initialLoading = true this.syncError = { - type: ERROR_TYPE.SAVE_COLLISSION, + type: error, data: data } - this.tiptap.setOptions({ editable: false }) - + } + if (error === ERROR_TYPE.CONNECTION_FAILED) { + this.initialLoading = false + // FIXME: ideally we just try to reconnect in the service, so we don't loose steps + OC.Notification.showTemporary('Connection failed, reconnecting') + this.reconnect() + } + if (error === ERROR_TYPE.SOURCE_NOT_FOUND) { + this.initialLoading = false + OC.Notification.showTemporary('Source not found') + this.$emit('close') } }) .on('stateChange', (state) => { @@ -335,6 +345,11 @@ export default { resolveUseServerVersion() { this.forceRecreate = true + this.reconnect() + }, + + reconnect() { + this.forceRecreate = true this.syncService.close() this.syncService = null this.tiptap.destroy() diff --git a/src/services/PollingBackend.js b/src/services/PollingBackend.js index b650516f0..a41d1353f 100644 --- a/src/services/PollingBackend.js +++ b/src/services/PollingBackend.js @@ -145,6 +145,8 @@ class PollingBackend { this._authority.emit('error', ERROR_TYPE.SAVE_COLLISSION, { outsideChange: e.response.data.outsideChange }) + } else if (e.response.status === 403) { + this._authority.emit('error', ERROR_TYPE.CONNECTION_FAILED, {}) } else { console.error('Failed to fetch steps due to other reason', e) } @@ -179,6 +181,15 @@ class PollingBackend { }).catch((e) => { console.error('failed to apply steps due to collission, retrying') this.lock = false + if (!e.response) { + throw e + } + // Only emit conflict event if we have synced until the latest version + if (e.response.status === 403 && e.response.data.document.currentVersion === this._authority.document.currentVersion) { + this._authority.emit('error', ERROR_TYPE.PUSH_FAILURE, {}) + OC.Notification.showTemporary('Changes could not be sent yet') + } + this.fetchSteps() this.carefulRetry() }) diff --git a/src/services/SyncService.js b/src/services/SyncService.js index 306ffc5f8..2d7a95829 100644 --- a/src/services/SyncService.js +++ b/src/services/SyncService.js @@ -42,7 +42,11 @@ const ERROR_TYPE = { */ PUSH_FAILURE: 1, - LOAD_ERROR: 2 + LOAD_ERROR: 2, + + CONNECTION_FAILED: 3, + + SOURCE_NOT_FOUND: 4 } class SyncService { |