Fix api errors not being displayed properly

This commit is contained in:
Björn Fromme
2022-11-11 13:49:41 +01:00
parent c56b22d2ef
commit 3ca24a4fb1
3 changed files with 35 additions and 22 deletions
@@ -145,8 +145,8 @@
</template> </template>
</collapsible-panel> </collapsible-panel>
</div> </div>
<div class="py-4 lg:flex lg:justify-between space-y-1 lg:space-y-0" v-show="!loading"> <div class="py-4 lg:flex lg:justify-between space-y-1 lg:space-y-0" v-show="!loading" v-if="initialized">
<button class="button bg-button" :disabled="!dirty" @click.prevent="storeBookingData()" v-if="initialized"> <button class="button bg-button" :disabled="!dirty" @click.prevent="storeBookingData()">
Buchung aktualisieren Buchung aktualisieren
</button> </button>
<router-link :to="{ name: 'events' }" class="button bg-button"> <router-link :to="{ name: 'events' }" class="button bg-button">
@@ -157,7 +157,6 @@
</template> </template>
<script> <script>
import Vue from 'vue'
import AccommodationSelect from './components/AccommodationSelect' import AccommodationSelect from './components/AccommodationSelect'
import ContingentsOverview from './components/ContingentsOverview' import ContingentsOverview from './components/ContingentsOverview'
import MutableFields from './components/MutableFields' import MutableFields from './components/MutableFields'
@@ -171,7 +170,7 @@
import ServicesOverview from './components/ServicesOverview' import ServicesOverview from './components/ServicesOverview'
import TransportationSelect from './components/TransportationSelect' import TransportationSelect from './components/TransportationSelect'
import { mapGetters, mapMutations, mapState } from 'vuex' import { mapGetters, mapMutations, mapState } from 'vuex'
import {checkStatus, defaultOptions, handleError} from './api' import {checkStatus, defaultOptions} from './api'
export default { export default {
name: 'BookingEdit', name: 'BookingEdit',
@@ -232,7 +231,6 @@
this.participantData = data.participantData this.participantData = data.participantData
this.travelData = data.travelData this.travelData = data.travelData
}) })
.catch(handleError)
.finally(() => { .finally(() => {
this.endLoading() this.endLoading()
}) })
@@ -533,9 +531,9 @@
}) })
.catch(error => { .catch(error => {
this.alert({ this.alert({
message: error.message, message: 'Es ist ein Fehler aufgetreten: ' + error.message,
success: false, success: false,
}); })
}) })
} }
} }
@@ -9,17 +9,12 @@ function checkStatus(response) {
if (response.ok) { if (response.ok) {
return response return response
} else { } else {
const error = new Error(response.statusText) return response
error.response = response.json() .json()
throw error .then(error => {
} throw Error(error.message)
}
function handleError() {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten :(',
success: false,
}) })
} }
}
export { checkStatus, handleError, defaultOptions } export { checkStatus, defaultOptions }
@@ -101,7 +101,12 @@ export default new Vuex.Store({
.then(data => { .then(data => {
commit('setCountries', data) commit('setCountries', data)
}) })
.catch(handleError) .catch(error => {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten: ' + error.message,
success: false,
})
})
.finally(() => { .finally(() => {
commit('endLoading') commit('endLoading')
}) })
@@ -184,7 +189,12 @@ export default new Vuex.Store({
.then(checkStatus) .then(checkStatus)
.then(response => response.json()) .then(response => response.json())
.then(data => data) .then(data => data)
.catch(handleError) .catch(error => {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten: ' + error.message,
success: false,
})
})
.finally(() => { .finally(() => {
commit('endLoading') commit('endLoading')
}) })
@@ -205,7 +215,12 @@ export default new Vuex.Store({
commit('setWatchlist', data.watchlist) commit('setWatchlist', data.watchlist)
} }
}) })
.catch(handleError) .catch(error => {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten: ' + error.message,
success: false,
})
})
.finally(() => { .finally(() => {
commit('endLoading') commit('endLoading')
}) })
@@ -228,7 +243,12 @@ export default new Vuex.Store({
success: true, success: true,
}) })
}) })
.catch(handleError) .catch(error => {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten: ' + error.message,
success: false,
})
})
.finally(() => { .finally(() => {
commit('endLoading') commit('endLoading')
}) })