Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2021-03-14 12:06:12 +0300
committerdartcafe <github@dartcafe.de>2021-03-14 12:06:12 +0300
commit400902985d06f537fe0e138b924c7e6a8e9402ce (patch)
tree057b5d9240b1008e9bcc162907f9d7c668164b89 /src/js/mixins
parent8f1d0143569d20a16431399a008328ef4616b84e (diff)
enhanced error handling in watchPolls
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'src/js/mixins')
-rw-r--r--src/js/mixins/watchPolls.js63
1 files changed, 37 insertions, 26 deletions
diff --git a/src/js/mixins/watchPolls.js b/src/js/mixins/watchPolls.js
index e8b0d1ab..72c62ba4 100644
--- a/src/js/mixins/watchPolls.js
+++ b/src/js/mixins/watchPolls.js
@@ -1,6 +1,7 @@
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
+import exception from '../Exceptions/Exceptions'
export const watchPolls = {
data() {
@@ -29,29 +30,25 @@ export const watchPolls = {
if (item.table === 'polls') {
if (this.$route.name !== 'publicVote') {
// load poll list only, when not in public poll
- dispatches.push('polls/list')
+ dispatches = [...dispatches, 'polls/list']
}
if (item.pollId === parseInt(this.$route.params.id ?? this.$store.state.share.pollId)) {
// if current poll is affected, load current poll configuration
- dispatches.push('poll/get')
// load also options and votes
- dispatches.push('votes/list')
- dispatches.push('options/list')
+ dispatches = [...dispatches, 'poll/get', 'votes/list', 'options/list']
}
} else if (['votes', 'options'].includes(item.table)) {
- dispatches.push('votes/list')
- dispatches.push('options/list')
+ dispatches = [...dispatches, 'votes/list', 'options/list']
} else {
// a table of the current poll was reported, load
// corresponding stores
- dispatches.push(item.table + '/list')
+ dispatches = [...dispatches, item.table + '/list']
}
})
+
// remove duplicates
dispatches = [...new Set(dispatches)]
- // execute all loads within one promise
- const requests = dispatches.map(dispatches => this.$store.dispatch(dispatches))
- await Promise.all(requests)
+ await Promise.all(dispatches.map(dispatches => this.$store.dispatch(dispatches)))
},
async watchPolls() {
@@ -72,36 +69,50 @@ export const watchPolls = {
params: { offset: this.lastUpdated },
cancelToken: this.cancelToken.token,
})
- console.debug('polls', 'update detected', response.data.updates)
- this.retryCounter = 0
- await this.loadTables(response.data.updates)
+
+ if (typeof response.data?.updates !== 'object') {
+ console.debug('return value is no array')
+ throw exception('Invalid content')
+ }
+ if (this.retryCounter) {
+ // timeout happened after connection errors
+ this.retryCounter = 0
+ } else {
+ // If server responds with an HTML-Page like the update page,
+ // throw an simple exception
+ console.debug('polls', 'update detected', response.data.updates)
+ await this.loadTables(response.data.updates)
+ }
} catch (e) {
if (axios.isCancel(e)) {
if (this.restart) {
- console.debug('restart watch')
+ // Restarting of poll was initiated
+ console.debug('watch canceled - restart watch')
this.retryCounter = 0
this.restart = false
this.cancelToken = axios.CancelToken.source()
} else {
- console.debug('Watch canceled')
+ // request got canceled by a user invention
+ // we will exit here
+ console.debug('watch canceled')
return
}
- } else if (e.response) {
- if (e.response.status === 304) {
- // timeout of poll --> restart
+ } else if (e.response?.status === 304) {
+ // the request timed out without updates
+ // this is expected --> restart
+ if (this.retryCounter) {
+ // timeout happened after connection errors
this.retryCounter = 0
- } else {
- this.retryCounter++
- console.error('Unhandled error watching polls', e)
- console.debug('error request', this.retryCounter)
- await new Promise(resolve => setTimeout(resolve, this.retryTimeout))
}
- } else if (e.request) {
+ } else {
+ // No response was returned, i.e. server died or exception was triggered
this.retryCounter++
- console.debug('No response - request aborted')
- console.debug('failed request', this.retryCounter)
+ if (e.response) {
+ console.error('Unhandled error watching polls', e)
+ }
+ console.debug('No response - request aborted - failed request', this.retryCounter)
await new Promise(resolve => setTimeout(resolve, this.retryTimeout))
}
}