diff --git a/src/js/Api/modules/polls.js b/src/js/Api/modules/polls.js index 1e3ee49e3..4a4250624 100644 --- a/src/js/Api/modules/polls.js +++ b/src/js/Api/modules/polls.js @@ -3,6 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ import { httpInstance, createCancelTokenHandler } from './HttpApi.js' +import {InvalidPollID} from '../../Exceptions/Exceptions.js' const polls = { getPolls() { @@ -33,6 +34,9 @@ const polls = { }, watchPoll(pollId = 0, lastUpdated) { + if (!pollId) { + return Promise.reject(new InvalidPollID("missing poll ID")) + } return httpInstance.request({ method: 'GET', url: `poll/${pollId}/watch`, diff --git a/src/js/Exceptions/Exceptions.js b/src/js/Exceptions/Exceptions.js index cd5884122..646350b14 100644 --- a/src/js/Exceptions/Exceptions.js +++ b/src/js/Exceptions/Exceptions.js @@ -21,6 +21,15 @@ class NotReady extends Error { } +class InvalidPollID extends Error { + + constructor(message) { + super(message) + this.name = 'InvalidPollID' + } + +} + class InvalidJSON extends Error { constructor(message) { @@ -30,4 +39,4 @@ class InvalidJSON extends Error { } -export { Exception, InvalidJSON, NotReady } +export { Exception, InvalidPollID, InvalidJSON, NotReady } diff --git a/src/js/mixins/watchPolls.js b/src/js/mixins/watchPolls.js index c39b649fe..24cb4b952 100644 --- a/src/js/mixins/watchPolls.js +++ b/src/js/mixins/watchPolls.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ import { mapState } from 'vuex' -import { InvalidJSON } from '../Exceptions/Exceptions.js' +import { InvalidJSON, InvalidPollID } from '../Exceptions/Exceptions.js' import { PollsAPI, PublicAPI } from '../Api/index.js' import { emit } from '@nextcloud/event-bus' import { Logger } from '../helpers/index.js' @@ -104,13 +104,18 @@ export const watchPolls = { }, async handleConnectionException(error) { - if (error.response?.status === 304) { + if (error?.response?.status === 304) { // this is a wanted response, no updates where found. // resume to normal operation Logger.debug(`No updates - continue ${this.updateType}`) this.retryCounter = 0 return } + + if(error instanceof InvalidPollID) { + Logger.debug('No pollId provided - abort watch') + return + } if (error?.code === 'ERR_NETWORK') { Logger.debug(`Possibly offline - continue ${this.updateType}`)