diff options
author | dartcafe <github@dartcafe.de> | 2022-06-22 21:43:58 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2022-06-22 21:43:58 +0300 |
commit | d52eda2071eccaaf7a729d133392ce8d91265eac (patch) | |
tree | c6b1c2f6b5b585b02435b7fb92b3a19d249601f4 /src | |
parent | 717d75772558704ff18f0020dd905ab59d9c806b (diff) |
Accept: 'application/json' in http headersref/watch-error-handling
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'src')
24 files changed, 273 insertions, 302 deletions
diff --git a/src/js/components/Poll/PublicEmail.vue b/src/js/components/Poll/PublicEmail.vue index 4c56d94f..3f227744 100644 --- a/src/js/components/Poll/PublicEmail.vue +++ b/src/js/components/Poll/PublicEmail.vue @@ -101,7 +101,9 @@ export default { } else { try { this.checking = true - await axios.get(`${generateUrl('apps/polls/check/emailaddress')}/${this.emailAddress}`) + await axios.get(`${generateUrl('apps/polls/check/emailaddress')}/${this.emailAddress}`, { + headers: { Accept: 'application/json' }, + }) this.checkResult = t('polls', 'valid email address.') this.checkStatus = 'success' } catch { diff --git a/src/js/components/Poll/PublicRegisterModal.vue b/src/js/components/Poll/PublicRegisterModal.vue index fe8a535c..e7ab2452 100644 --- a/src/js/components/Poll/PublicRegisterModal.vue +++ b/src/js/components/Poll/PublicRegisterModal.vue @@ -285,8 +285,14 @@ export default { }, validatePublicUsername: debounce(async function() { + const endpoint = 'apps/polls/check/username' + try { - await axios.post(generateUrl('apps/polls/check/username'), { userName: this.userName, token: this.$route.params.token }) + await axios.post(generateUrl(endpoint), { + headers: { Accept: 'application/json' }, + userName: this.userName, + token: this.$route.params.token, + }) this.isValidName = true } catch { this.isValidName = false @@ -295,8 +301,12 @@ export default { }, 500), validateEmailAddress: debounce(async function() { + const endpoint = `apps/polls/check/emailaddress/${this.emailAddress}` + try { - await axios.get(`${generateUrl('apps/polls/check/emailaddress')}/${this.emailAddress}`) + await axios.get(generateUrl(endpoint), { + headers: { Accept: 'application/json' }, + }) this.isValidEmailAddress = true } catch { this.isValidEmailAddress = false diff --git a/src/js/components/Settings/AdminSettings/AdminCombo.vue b/src/js/components/Settings/AdminSettings/AdminCombo.vue index 70e2ec44..ea0c7e79 100644 --- a/src/js/components/Settings/AdminSettings/AdminCombo.vue +++ b/src/js/components/Settings/AdminSettings/AdminCombo.vue @@ -45,11 +45,8 @@ <script> -import debounce from 'lodash/debounce' -import { mapState } from 'vuex' -import axios from '@nextcloud/axios' -import { generateUrl } from '@nextcloud/router' import { CheckboxRadioSwitch, Multiselect } from '@nextcloud/vue' +import { loadGroups, writeValue } from '../../../mixins/adminSettingsMixin.js' export default { name: 'AdminCombo', @@ -59,19 +56,9 @@ export default { Multiselect, }, - data() { - return { - searchToken: null, - groups: [], - isLoading: false, - } - }, + mixins: [loadGroups, writeValue], computed: { - ...mapState({ - appSettings: (state) => state.appSettings, - }), - // Add bindings comboLimited: { get() { @@ -90,41 +77,5 @@ export default { }, }, }, - - created() { - this.loadGroups('') - }, - - methods: { - async writeValue(value) { - await this.$store.commit('appSettings/set', value) - this.$store.dispatch('appSettings/write') - }, - loadGroups: debounce(async function(query) { - let endPoint = generateUrl(`apps/polls/groups/${query}`) - - if (!query.trim()) { - endPoint = generateUrl('apps/polls/groups') - } - this.isLoading = true - - if (this.searchToken) { - this.searchToken.cancel() - } - this.searchToken = axios.CancelToken.source() - try { - const response = await axios.get(endPoint, { cancelToken: this.searchToken.token }) - this.groups = response.data.groups - this.isLoading = false - } catch (e) { - if (axios.isCancel(e)) { - // request was cancelled - } else { - console.error(e.response) - this.isLoading = false - } - } - }, 250), - }, } </script> diff --git a/src/js/components/Settings/AdminSettings/AdminHideMailAddresses.vue b/src/js/components/Settings/AdminSettings/AdminHideMailAddresses.vue index 34523f85..8f2701bc 100644 --- a/src/js/components/Settings/AdminSettings/AdminHideMailAddresses.vue +++ b/src/js/components/Settings/AdminSettings/AdminHideMailAddresses.vue @@ -45,11 +45,8 @@ <script> -import debounce from 'lodash/debounce' -import { mapState } from 'vuex' -import axios from '@nextcloud/axios' -import { generateUrl } from '@nextcloud/router' import { CheckboxRadioSwitch, Multiselect } from '@nextcloud/vue' +import { loadGroups, writeValue } from '../../../mixins/adminSettingsMixin.js' export default { name: 'AdminHideMailAddresses', @@ -59,19 +56,9 @@ export default { Multiselect, }, - data() { - return { - searchToken: null, - groups: [], - isLoading: false, - } - }, + mixins: [loadGroups, writeValue], computed: { - ...mapState({ - appSettings: (state) => state.appSettings, - }), - // Add bindings hideMailAddresses: { get() { @@ -90,42 +77,5 @@ export default { }, }, }, - - created() { - this.loadGroups('') - }, - - methods: { - async writeValue(value) { - await this.$store.commit('appSettings/set', value) - this.$store.dispatch('appSettings/write') - }, - - loadGroups: debounce(async function(query) { - let endPoint = generateUrl(`apps/polls/groups/${query}`) - - if (!query.trim()) { - endPoint = generateUrl('apps/polls/groups') - } - this.isLoading = true - - if (this.searchToken) { - this.searchToken.cancel() - } - this.searchToken = axios.CancelToken.source() - try { - const response = await axios.get(endPoint, { cancelToken: this.searchToken.token }) - this.groups = response.data.groups - this.isLoading = false - } catch (e) { - if (axios.isCancel(e)) { - // request was cancelled - } else { - console.error(e.response) - this.isLoading = false - } - } - }, 250), - }, } </script> diff --git a/src/js/components/Settings/AdminSettings/AdminPollCreation.vue b/src/js/components/Settings/AdminSettings/AdminPollCreation.vue index 7195e10c..230f0d9b 100644 --- a/src/js/components/Settings/AdminSettings/AdminPollCreation.vue +++ b/src/js/components/Settings/AdminSettings/AdminPollCreation.vue @@ -45,10 +45,7 @@ <script> -import debounce from 'lodash/debounce' -import { mapState } from 'vuex' -import axios from '@nextcloud/axios' -import { generateUrl } from '@nextcloud/router' +import { loadGroups, writeValue } from '../../../mixins/adminSettingsMixin.js' import { CheckboxRadioSwitch, Multiselect } from '@nextcloud/vue' export default { @@ -59,19 +56,9 @@ export default { Multiselect, }, - data() { - return { - searchToken: null, - groups: [], - isLoading: false, - } - }, + mixins: [loadGroups, writeValue], computed: { - ...mapState({ - appSettings: (state) => state.appSettings, - }), - // Add bindings createPollLimited: { get() { @@ -90,41 +77,5 @@ export default { }, }, }, - - created() { - this.loadGroups('') - }, - - methods: { - async writeValue(value) { - await this.$store.commit('appSettings/set', value) - this.$store.dispatch('appSettings/write') - }, - loadGroups: debounce(async function(query) { - let endPoint = generateUrl(`apps/polls/groups/${query}`) - - if (!query.trim()) { - endPoint = generateUrl('apps/polls/groups') - } - this.isLoading = true - - if (this.searchToken) { - this.searchToken.cancel() - } - this.searchToken = axios.CancelToken.source() - try { - const response = await axios.get(endPoint, { cancelToken: this.searchToken.token }) - this.groups = response.data.groups - this.isLoading = false - } catch (e) { - if (axios.isCancel(e)) { - // request was cancelled - } else { - console.error(e.response) - this.isLoading = false - } - } - }, 250), - }, } </script> diff --git a/src/js/components/Settings/AdminSettings/AdminPollDownload.vue b/src/js/components/Settings/AdminSettings/AdminPollDownload.vue index 4384c02d..e8e8bb32 100644 --- a/src/js/components/Settings/AdminSettings/AdminPollDownload.vue +++ b/src/js/components/Settings/AdminSettings/AdminPollDownload.vue @@ -45,11 +45,8 @@ <script> -import debounce from 'lodash/debounce' -import { mapState } from 'vuex' -import axios from '@nextcloud/axios' -import { generateUrl } from '@nextcloud/router' import { CheckboxRadioSwitch, Multiselect } from '@nextcloud/vue' +import { loadGroups, writeValue } from '../../../mixins/adminSettingsMixin.js' export default { name: 'AdminPollDownload', @@ -59,19 +56,9 @@ export default { Multiselect, }, - data() { - return { - searchToken: null, - groups: [], - isLoading: false, - } - }, + mixins: [loadGroups, writeValue], computed: { - ...mapState({ - appSettings: (state) => state.appSettings, - }), - // Add bindings pollDownloadLimited: { get() { @@ -90,41 +77,5 @@ export default { }, }, }, - - created() { - this.loadGroups('') - }, - - methods: { - async writeValue(value) { - await this.$store.commit('appSettings/set', value) - this.$store.dispatch('appSettings/write') - }, - loadGroups: debounce(async function(query) { - let endPoint = generateUrl(`apps/polls/groups/${query}`) - - if (!query.trim()) { - endPoint = generateUrl('apps/polls/groups') - } - this.isLoading = true - - if (this.searchToken) { - this.searchToken.cancel() - } - this.searchToken = axios.CancelToken.source() - try { - const response = await axios.get(endPoint, { cancelToken: this.searchToken.token }) - this.groups = response.data.groups - this.isLoading = false - } catch (e) { - if (axios.isCancel(e)) { - // request was cancelled - } else { - console.error(e.response) - this.isLoading = false - } - } - }, 250), - }, } </script> diff --git a/src/js/components/Settings/AdminSettings/AdminShareSettings.vue b/src/js/components/Settings/AdminSettings/AdminShareSettings.vue index 977858dd..3ad4c362 100644 --- a/src/js/components/Settings/AdminSettings/AdminShareSettings.vue +++ b/src/js/components/Settings/AdminSettings/AdminShareSettings.vue @@ -64,11 +64,8 @@ <script> -import debounce from 'lodash/debounce' -import { mapState } from 'vuex' -import axios from '@nextcloud/axios' -import { generateUrl } from '@nextcloud/router' import { CheckboxRadioSwitch, Multiselect } from '@nextcloud/vue' +import { loadGroups, writeValue } from '../../../mixins/adminSettingsMixin.js' export default { name: 'AdminShareSettings', @@ -78,19 +75,9 @@ export default { Multiselect, }, - data() { - return { - searchToken: null, - groups: [], - isLoading: false, - } - }, + mixins: [loadGroups, writeValue], computed: { - ...mapState({ - appSettings: (state) => state.appSettings, - }), - // Add bindings publicSharesLimited: { get() { @@ -125,41 +112,5 @@ export default { }, }, }, - - created() { - this.loadGroups('') - }, - - methods: { - async writeValue(value) { - await this.$store.commit('appSettings/set', value) - this.$store.dispatch('appSettings/write') - }, - loadGroups: debounce(async function(query) { - let endPoint = generateUrl(`apps/polls/groups/${query}`) - - if (!query.trim()) { - endPoint = generateUrl('apps/polls/groups') - } - this.isLoading = true - - if (this.searchToken) { - this.searchToken.cancel() - } - this.searchToken = axios.CancelToken.source() - try { - const response = await axios.get(endPoint, { cancelToken: this.searchToken.token }) - this.groups = response.data.groups - this.isLoading = false - } catch (e) { - if (axios.isCancel(e)) { - // request was cancelled - } else { - console.error(e.response) - this.isLoading = false - } - } - }, 250), - }, } </script> diff --git a/src/js/components/User/UserMenu.vue b/src/js/components/User/UserMenu.vue index 0c998e81..dad7a9fd 100644 --- a/src/js/components/User/UserMenu.vue +++ b/src/js/components/User/UserMenu.vue @@ -185,10 +185,14 @@ export default { }, validateEmailAddress: debounce(async function(value) { + const endPoint = `apps/polls/check/emailaddress/${this.emailAddressTemp}` + this.emailAddressTemp = value try { this.checking = true - await axios.get(`${generateUrl('apps/polls/check/emailaddress')}/${this.emailAddressTemp}`) + await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) this.checkResult = t('polls', 'valid email address.') this.checkStatus = 'success' } catch { diff --git a/src/js/components/User/UserSearch.vue b/src/js/components/User/UserSearch.vue index d4bc06ac..677e2984 100644 --- a/src/js/components/User/UserSearch.vue +++ b/src/js/components/User/UserSearch.vue @@ -74,6 +74,8 @@ export default { methods: { loadUsersAsync: debounce(async function(query) { + const endPoint = `apps/polls/search/users/${query}` + if (!query) { this.users = [] return @@ -84,7 +86,10 @@ export default { } this.searchToken = axios.CancelToken.source() try { - const response = await axios.get(generateUrl(`apps/polls/search/users/${query}`), { cancelToken: this.searchToken.token }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + cancelToken: this.searchToken.token, + }) this.users = response.data.siteusers this.isLoading = false } catch (e) { diff --git a/src/js/mixins/adminSettingsMixin.js b/src/js/mixins/adminSettingsMixin.js new file mode 100644 index 00000000..c994f13b --- /dev/null +++ b/src/js/mixins/adminSettingsMixin.js @@ -0,0 +1,89 @@ +/* jshint esversion: 6 */ +/** + * @copyright Copyright (c) 2021 René Gieling <github@dartcafe.de> + * + * @author René Gieling <github@dartcafe.de> + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +import debounce from 'lodash/debounce' +import axios from '@nextcloud/axios' +import { generateUrl } from '@nextcloud/router' +import { mapState } from 'vuex' + +export const loadGroups = { + data() { + return { + searchToken: null, + groups: [], + isLoading: false, + } + }, + computed: { + ...mapState({ + appSettings: (state) => state.appSettings, + }), + }, + + created() { + this.loadGroups('') + }, + + methods: { + loadGroups: debounce(async function(query) { + let endPoint = 'apps/polls/groups' + + if (query.trim()) { + endPoint = `${endPoint}/${query}` + } + + this.isLoading = true + + if (this.searchToken) { + this.searchToken.cancel() + } + + this.searchToken = axios.CancelToken.source() + + try { + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + cancelToken: this.searchToken.token, + }) + this.groups = response.data.groups + this.isLoading = false + } catch (e) { + if (axios.isCancel(e)) { + // request was cancelled + } else { + console.error(e.response) + this.isLoading = false + } + } + }, 250), + }, +} + +export const writeValue = { + methods: { + async writeValue(value) { + await this.$store.commit('appSettings/set', value) + this.$store.dispatch('appSettings/write') + }, + }, +} diff --git a/src/js/mixins/watchPolls.js b/src/js/mixins/watchPolls.js index 65f486c1..aadfcbfb 100644 --- a/src/js/mixins/watchPolls.js +++ b/src/js/mixins/watchPolls.js @@ -128,6 +128,7 @@ export const watchPolls = { return await axios.get(generateUrl(this.endPoint), { params: { offset: this.lastUpdated }, cancelToken: this.cancelToken.token, + headers: { Accept: 'application/json' }, }) }, diff --git a/src/js/router.js b/src/js/router.js index 2883e95f..c6485944 100644 --- a/src/js/router.js +++ b/src/js/router.js @@ -51,7 +51,10 @@ Vue.use(Router) */ async function validateToken(to, from, next) { try { - const response = await axios.get(generateUrl(`apps/polls/s/${to.params.token}/share`), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(`apps/polls/s/${to.params.token}/share`), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) if (getCurrentUser()) { // reroute to the internal vote page, if the user is logged in next({ name: 'vote', params: { id: response.data.share.pollId } }) diff --git a/src/js/store/modules/appSettings.js b/src/js/store/modules/appSettings.js index 668a07a8..9f7a1f09 100644 --- a/src/js/store/modules/appSettings.js +++ b/src/js/store/modules/appSettings.js @@ -72,7 +72,10 @@ const actions = { async get(context) { const endPoint = 'apps/polls/settings/app' try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('set', response.data.appSettings) } catch { // context.commit('reset') @@ -82,7 +85,10 @@ const actions = { async write(context) { const endPoint = 'apps/polls/settings/app' try { - const response = await axios.post(generateUrl(endPoint), { appSettings: context.state }) + const response = await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + appSettings: context.state, + }) context.commit('set', response.data.appSettings) } catch (e) { console.error('Error writing appSettings', { error: e.response }, { appSettings: state }) diff --git a/src/js/store/modules/combo.js b/src/js/store/modules/combo.js index 78b35669..7a24e3b1 100644 --- a/src/js/store/modules/combo.js +++ b/src/js/store/modules/combo.js @@ -145,7 +145,10 @@ const actions = { async addPoll(context, payload) { const endPoint = `apps/polls/poll/${payload.pollId}/poll` try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('addPoll', response.data) } catch (e) { console.debug('Error loading poll for combo', { error: e.response }) @@ -156,7 +159,10 @@ const actions = { const endPoint = `apps/polls/poll/${payload.pollId}/options` try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('addOptions', response.data) } catch (e) { console.debug('Error loading options for combo', { error: e.response }) @@ -167,7 +173,10 @@ const actions = { const endPoint = `apps/polls/poll/${payload.pollId}/votes` try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('addVotes', response.data) } catch (e) { console.debug('Error loading options for combo', { error: e.response }) diff --git a/src/js/store/modules/comments.js b/src/js/store/modules/comments.js index 946cf300..be5207bc 100644 --- a/src/js/store/modules/comments.js +++ b/src/js/store/modules/comments.js @@ -71,7 +71,10 @@ const actions = { } try { - const response = await axios.get(generateUrl(`${endPoint}/comments`), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(`${endPoint}/comments`), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('set', response.data) } catch { context.commit('reset') @@ -93,7 +96,10 @@ const actions = { } try { - await axios.post(generateUrl(`${endPoint}/comment`), { message: payload.message }) + await axios.post(generateUrl(`${endPoint}/comment`), { + headers: { Accept: 'application/json' }, + message: payload.message, + }) context.dispatch('list') // context.commit('add', { comment: response.data.comment }) } catch (e) { @@ -110,7 +116,9 @@ const actions = { } try { - await axios.delete(generateUrl(`${endPoint}/comment/${payload.comment.id}`)) + await axios.delete(generateUrl(`${endPoint}/comment/${payload.comment.id}`), { + headers: { Accept: 'application/json' }, + }) context.commit('delete', { comment: payload.comment }) } catch (e) { console.error('Error deleting comment', { error: e.response }, { payload }) diff --git a/src/js/store/modules/options.js b/src/js/store/modules/options.js index 5f92d287..ab69a7ec 100644 --- a/src/js/store/modules/options.js +++ b/src/js/store/modules/options.js @@ -150,7 +150,10 @@ const actions = { } try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('set', { options: response.data.options }) } catch (e) { console.error('Error loding options', { error: e.response }, { pollId: context.rootState.route.params.id }) @@ -168,6 +171,7 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, pollId: context.rootState.route.params.id, timestamp: payload.timestamp, text: payload.text, @@ -186,6 +190,7 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, pollId: context.rootState.route.params.id, text: payload.text, }) @@ -202,6 +207,7 @@ const actions = { try { const response = await axios.put(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, timestamp: payload.option.timestamp, text: payload.option.timeStamp, duration: payload.option.duration, @@ -224,7 +230,9 @@ const actions = { } try { - await axios.delete(generateUrl(endPoint)) + await axios.delete(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) context.commit('delete', { option: payload.option }) } catch (e) { console.error('Error deleting option', { error: e.response }, { payload }) @@ -239,7 +247,9 @@ const actions = { context.commit('confirm', { option: payload.option }) try { - const response = await axios.put(generateUrl(endPoint)) + const response = await axios.put(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) context.commit('setItem', { option: response.data.option }) } catch (e) { console.error('Error confirming option', { error: e.response }, { payload }) @@ -255,6 +265,7 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, options: payload, }) context.commit('set', { options: response.data.options }) @@ -270,6 +281,7 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, step: payload.sequence.step, unit: payload.sequence.unit.value, amount: payload.sequence.amount, @@ -287,6 +299,7 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, step: payload.shift.step, unit: payload.shift.unit.value, }) @@ -303,9 +316,8 @@ const actions = { try { return await axios.get(generateUrl(endPoint), { - params: { - tz: Intl.DateTimeFormat().resolvedOptions().timeZone, - }, + headers: { Accept: 'application/json' }, + params: { tz: Intl.DateTimeFormat().resolvedOptions().timeZone }, }) } catch (e) { return { events: [] } diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js index 655d99de..e01a6769 100644 --- a/src/js/store/modules/poll.js +++ b/src/js/store/modules/poll.js @@ -187,7 +187,10 @@ const actions = { return } try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('set', response.data) context.commit('acl/set', response.data) } catch (e) { @@ -199,7 +202,11 @@ const actions = { async add(context, payload) { const endPoint = 'apps/polls/poll/add' try { - return await axios.post(generateUrl(endPoint), { title: payload.title, type: payload.type }) + return await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + title: payload.title, + type: payload.type, + }) } catch (e) { console.error('Error adding poll:', { error: e.response }, { state: context.state }) throw e @@ -218,7 +225,10 @@ const actions = { async update(context) { const endPoint = `apps/polls/poll/${context.state.id}` try { - const response = await axios.put(generateUrl(endPoint), { poll: context.state }) + const response = await axios.put(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + poll: context.state, + }) context.commit('set', response.data) context.commit('acl/set', response.data) context.dispatch('options/list', null, { root: true }) @@ -240,7 +250,9 @@ const actions = { async delete(context, payload) { const endPoint = `apps/polls/poll/${payload.pollId}` try { - await axios.delete(generateUrl(endPoint)) + await axios.delete(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) } catch (e) { console.error('Error deleting poll', { error: e.response }, { payload }) } @@ -249,7 +261,9 @@ const actions = { async getParticipantsEmailAddresses(context) { const endPoint = `apps/polls/poll/${context.state.id}/addresses` try { - return await axios.get(generateUrl(endPoint)) + return await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) } catch (e) { console.error('Error retrieving email addresses', { error: e.response }) } diff --git a/src/js/store/modules/polls.js b/src/js/store/modules/polls.js index 9bc57165..2477ad20 100644 --- a/src/js/store/modules/polls.js +++ b/src/js/store/modules/polls.js @@ -199,7 +199,10 @@ const actions = { const endPoint = 'apps/polls/polls' try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('set', { list: response.data.list }) context.commit('setPollCreationAllowed', { pollCreationAllowed: response.data.pollCreationAllowed }) context.commit('setComboAllowed', { comboAllowed: response.data.comboAllowed }) diff --git a/src/js/store/modules/pollsAdmin.js b/src/js/store/modules/pollsAdmin.js index 8e94a46f..52076bf1 100644 --- a/src/js/store/modules/pollsAdmin.js +++ b/src/js/store/modules/pollsAdmin.js @@ -51,7 +51,10 @@ const actions = { const endPoint = 'apps/polls/administration/polls' try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('set', { list: response.data }) } catch (e) { console.error('Error loading polls', { error: e.response }) @@ -64,7 +67,9 @@ const actions = { } const endPoint = `apps/polls/administration/poll/${payload.pollId}/takeover` - axios.put(generateUrl(endPoint)) + axios.put(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) }, } diff --git a/src/js/store/modules/settings.js b/src/js/store/modules/settings.js index 655ef667..857b11b8 100644 --- a/src/js/store/modules/settings.js +++ b/src/js/store/modules/settings.js @@ -229,14 +229,20 @@ const actions = { }, async setPollCombo(context, payload) { - await context.commit('setPollCombo', { pollCombo: payload.pollCombo }) + await context.commit('setPollCombo', { + headers: { Accept: 'application/json' }, + pollCombo: payload.pollCombo, + }) context.dispatch('write') }, async write(context) { const endPoint = 'apps/polls/preferences' try { - const response = await axios.post(generateUrl(endPoint), { settings: context.state.user }) + const response = await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + settings: context.state.user, + }) context.commit('setPreference', response.data.preferences) } catch (e) { console.error('Error writing preferences', { error: e.response }, { preferences: state.user }) @@ -246,7 +252,9 @@ const actions = { async getCalendars(context) { const endPoint = 'apps/polls/calendars' - const response = await axios.get(generateUrl(endPoint)) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) context.commit('setCalendars', { calendars: response.data.calendars }) return response }, diff --git a/src/js/store/modules/share.js b/src/js/store/modules/share.js index b01dd625..9601f1a0 100644 --- a/src/js/store/modules/share.js +++ b/src/js/store/modules/share.js @@ -65,7 +65,10 @@ const actions = { const endPoint = `apps/polls/s/${context.rootState.route.params.token}/share` try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('set', { share: response.data.share }) return response.data } catch (e) { @@ -83,6 +86,7 @@ const actions = { try { const response = await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, userName: payload.userName, emailAddress: payload.emailAddress, }) @@ -109,6 +113,7 @@ const actions = { try { const response = await axios.put(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, emailAddress: payload.emailAddress, }) context.commit('set', { share: response.data.share }) @@ -127,7 +132,9 @@ const actions = { const endPoint = `apps/polls/s/${context.rootState.route.params.token}/email` try { - const response = await axios.delete(generateUrl(endPoint)) + const response = await axios.delete(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) context.commit('set', { share: response.data.share }) context.dispatch('subscription/update', false, { root: true }) context.dispatch('poll/get', null, { root: true }) @@ -145,7 +152,9 @@ const actions = { const endPoint = `apps/polls/s/${context.rootState.route.params.token}/resend` try { - return await axios.put(generateUrl(endPoint)) + return await axios.put(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) } catch (e) { console.error('Error sending invitation', { error: e.response }, { payload }) throw e diff --git a/src/js/store/modules/shares.js b/src/js/store/modules/shares.js index 2281fef0..519603eb 100644 --- a/src/js/store/modules/shares.js +++ b/src/js/store/modules/shares.js @@ -75,7 +75,10 @@ const actions = { const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/shares` try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('set', response.data) } catch (e) { console.error('Error loading shares', { error: e.response }, { pollId: context.rootState.route.params.id }) @@ -87,7 +90,10 @@ const actions = { const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/share` try { - await axios.post(generateUrl(endPoint), payload.share) + await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + ...payload.share, + }) } catch (e) { console.error('Error writing share', { error: e.response }, { payload }) throw e @@ -102,7 +108,9 @@ const actions = { context.commit('delete', { share: payload.share }) try { - await axios.delete(generateUrl(endPoint)) + await axios.delete(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) } catch (e) { console.error('Error removing share', { error: e.response }, { payload }) throw e @@ -121,7 +129,9 @@ const actions = { } try { - await axios.put(generateUrl(endPoint)) + await axios.put(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) } catch (e) { console.error('Error switching type', { error: e.response }, { payload }) throw e @@ -134,7 +144,9 @@ const actions = { const endPoint = `apps/polls/share/${payload.share.token}/publicpollemail/${payload.value}` try { - await axios.put(generateUrl(endPoint)) + await axios.put(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) } catch (e) { console.error('Error changing email register setting', { error: e.response }, { payload }) throw e @@ -147,7 +159,9 @@ const actions = { const endPoint = `apps/polls/share/${payload.share.token}/invite` try { - return await axios.post(generateUrl(endPoint)) + return await axios.post(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) } catch (e) { console.error('Error sending invitation', { error: e.response }, { payload }) throw e @@ -160,7 +174,9 @@ const actions = { const endPoint = `apps/polls/share/${payload.share.token}/resolve` try { - await axios.get(generateUrl(endPoint)) + await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) } catch (e) { console.error('Error exploding group', e.response.data, { error: e.response }, { payload }) throw e diff --git a/src/js/store/modules/subscription.js b/src/js/store/modules/subscription.js index 44c0573e..aac566b1 100644 --- a/src/js/store/modules/subscription.js +++ b/src/js/store/modules/subscription.js @@ -59,7 +59,10 @@ const actions = { } try { - const response = await axios.get(generateUrl(endPoint), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) context.commit('set', response.data) } catch { context.commit('set', false) @@ -79,7 +82,9 @@ const actions = { } try { - const response = await axios.put(generateUrl(endPoint)) + const response = await axios.put(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) context.commit('set', response.data) } catch (e) { console.error(e.response) diff --git a/src/js/store/modules/votes.js b/src/js/store/modules/votes.js index 124b10fe..e62e319d 100644 --- a/src/js/store/modules/votes.js +++ b/src/js/store/modules/votes.js @@ -92,7 +92,10 @@ const actions = { return } try { - const response = await axios.get(generateUrl(`${endPoint}/votes`), { params: { time: +new Date() } }) + const response = await axios.get(generateUrl(`${endPoint}/votes`), { + headers: { Accept: 'application/json' }, + params: { time: +new Date() }, + }) const votes = [] response.data.votes.forEach((vote) => { if (vote.answer === 'yes') { @@ -122,6 +125,7 @@ const actions = { try { const response = await axios.put(generateUrl(`${endPoint}/vote`), { + headers: { Accept: 'application/json' }, optionId: payload.option.id, setTo: payload.setTo, }) @@ -150,7 +154,9 @@ const actions = { } try { - const response = await axios.delete(generateUrl(endPoint)) + const response = await axios.delete(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) context.commit('deleteVotes', { userId: response.data.deleted }) } catch (e) { console.error('Error deleting votes', { error: e.response }) @@ -161,7 +167,9 @@ const actions = { async deleteUser(context, payload) { const endPoint = `apps/polls/poll/${context.rootState.route.params.id}/user/${payload.userId}` try { - await axios.delete(generateUrl(endPoint)) + await axios.delete(generateUrl(endPoint), { + headers: { Accept: 'application/json' }, + }) context.commit('deleteVotes', payload) } catch (e) { console.error('Error deleting votes', { error: e.response }, { payload }) |