Skip to content

Commit

Permalink
fix: pollId equals 0
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
  • Loading branch information
hamza221 committed Aug 15, 2024
1 parent ecbf73f commit 8899710
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/js/Api/modules/polls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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`,
Expand Down
11 changes: 10 additions & 1 deletion src/js/Exceptions/Exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -30,4 +39,4 @@ class InvalidJSON extends Error {

}

export { Exception, InvalidJSON, NotReady }
export { Exception, InvalidPollID, InvalidJSON, NotReady }
9 changes: 7 additions & 2 deletions src/js/mixins/watchPolls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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}`)
Expand Down

0 comments on commit 8899710

Please sign in to comment.