From 3f368a794689856b4c70acb19a3417849099d620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 7 Dec 2022 19:08:31 +0100 Subject: [PATCH] Fix incomplete handling of validation errors of api calls --- .../Private/Assets/js/myep/Address.vue | 18 ++++++++---------- .../Private/Assets/js/myep/BookingEdit.vue | 4 +++- .../Private/Assets/js/myep/api/index.js | 6 +++++- .../Private/Assets/js/myep/store/index.js | 15 +++++++-------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Address.vue b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Address.vue index f903dc6c..91f35376 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Address.vue +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Address.vue @@ -106,22 +106,20 @@ save () { this.formErrors = {} this.saveAddress(this.userData) - .then(() => { - this.$emit('loaded') - }) .catch(error => { this.alert({ message: 'Bitte überprüfe deine Eingaben.', success: false, }) - error.response.then(data => { - const violations = data.violations - if (typeof violations !== 'undefined') { - for (let violation of violations) { - this.$set(this.formErrors, violation.property_path, violation.message) - } + const violations = error.violations + if (typeof violations !== 'undefined') { + for (let violation of violations) { + this.$set(this.formErrors, violation.property_path, violation.message) } - }) + } + }) + .finally(() => { + this.$emit('loaded') }) } }, diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/BookingEdit.vue b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/BookingEdit.vue index 59a374aa..84726350 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/BookingEdit.vue +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/BookingEdit.vue @@ -527,7 +527,6 @@ .then(() => this.loadServices()) .then(() => { this.initialized = true; - this.$emit('loaded') }) .catch(error => { this.alert({ @@ -535,6 +534,9 @@ success: false, }) }) + .finally(() => { + this.$emit('loaded') + }) } } diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/api/index.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/api/index.js index d5e7f2f2..35a2b5cc 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/api/index.js +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/api/index.js @@ -12,7 +12,11 @@ function checkStatus(response) { return response .json() .then(error => { - throw Error(error.message) + const responseError = new Error(error.message) + if (error.hasOwnProperty('violations')) { + responseError.violations = error.violations + } + throw responseError }) } } diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/store/index.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/store/index.js index 980e1d55..421c6333 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/store/index.js +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/store/index.js @@ -1,6 +1,6 @@ import Vue from 'vue' import Vuex from 'vuex' -import { checkStatus, handleError, defaultOptions } from '../api' +import { checkStatus, defaultOptions } from '../api' const configElement = document.getElementById('appconfig') const config = JSON.parse(configElement.innerHTML) @@ -171,7 +171,12 @@ export default new Vuex.Store({ .then(checkStatus) .then(response => response.json()) .then(response => response) - .catch(handleError) + .catch(error => { + commit('alert', { + message: 'Es ist ein Fehler aufgetreten: ' + error.message, + success: false, + }) + }) .finally(() => { commit('endLoading') }) @@ -243,12 +248,6 @@ export default new Vuex.Store({ success: true, }) }) - .catch(error => { - commit('alert', { - message: 'Es ist ein Fehler aufgetreten: ' + error.message, - success: false, - }) - }) .finally(() => { commit('endLoading') })