diff --git a/src/boot/axios.js b/src/boot/axios.js index 3bd80f487..aee38e887 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -39,37 +39,7 @@ const onResponse = (response) => { const onResponseError = (error) => { stateQuery.remove(error.config); - let message = ''; - - const response = error.response; - const responseData = response && response.data; - const responseError = responseData && response.data.error; - if (responseError) { - message = responseError.message; - } - - switch (response?.status) { - case 422: - if (error.name == 'ValidationError') - message += - ' "' + - responseError.details.context + - '.' + - Object.keys(responseError.details.codes).join(',') + - '"'; - break; - case 500: - message = 'errors.statusInternalServerError'; - break; - case 502: - message = 'errors.statusBadGateway'; - break; - case 504: - message = 'errors.statusGatewayTimeout'; - break; - } - - if (session.isLoggedIn() && response?.status === 401) { + if (session.isLoggedIn() && error.response?.status === 401) { session.destroy(false); const hash = window.location.hash; const url = hash.slice(1); @@ -78,8 +48,6 @@ const onResponseError = (error) => { return Promise.reject(error); } - notify(message, 'negative'); - return Promise.reject(error); }; diff --git a/src/boot/quasar.js b/src/boot/quasar.js index 5db6edd24..7845719fe 100644 --- a/src/boot/quasar.js +++ b/src/boot/quasar.js @@ -3,14 +3,51 @@ import qFormMixin from './qformMixin'; import mainShortcutMixin from './mainShortcutMixin'; import keyShortcut from './keyShortcut'; import useNotify from 'src/composables/useNotify.js'; +import { CanceledError } from 'axios'; + const { notify } = useNotify(); export default boot(({ app }) => { app.mixin(qFormMixin); app.mixin(mainShortcutMixin); app.directive('shortcut', keyShortcut); - app.config.errorHandler = function (err) { - console.error(err); - notify('globals.error', 'negative', 'error'); + app.config.errorHandler = (error) => { + let message; + const response = error.response; + const responseData = response?.data; + const responseError = responseData && response.data.error; + if (responseError) { + message = responseError.message; + } + + switch (response?.status) { + case 422: + if (error.name == 'ValidationError') + message += + ' "' + + responseError.details.context + + '.' + + Object.keys(responseError.details.codes).join(',') + + '"'; + break; + case 500: + message = 'errors.statusInternalServerError'; + break; + case 502: + message = 'errors.statusBadGateway'; + break; + case 504: + message = 'errors.statusGatewayTimeout'; + break; + } + + console.error(error); + if (error instanceof CanceledError) { + const env = process.env.NODE_ENV; + if (env && env !== 'development') return; + message = 'Duplicate request'; + } + + notify(message ?? 'globals.error', 'negative', 'error'); }; }); diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index 05f947cf3..9ac2d38a5 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -217,9 +217,6 @@ async function save() { updateAndEmit('onDataSaved', formData.value, response?.data); if ($props.reload) await arrayData.fetch({}); hasChanges.value = false; - } catch (err) { - console.error(err); - notify('errors.writeRequest', 'negative'); } finally { isLoading.value = false; } diff --git a/src/components/FormModelPopup.vue b/src/components/FormModelPopup.vue index 118c8f5f4..d91f07535 100644 --- a/src/components/FormModelPopup.vue +++ b/src/components/FormModelPopup.vue @@ -61,6 +61,7 @@ defineExpose({ :loading="isLoading" @click="emit('onDataCanceled')" v-close-popup + data-cy="FormModelPopup_cancel" /> diff --git a/src/components/VnSelectProvince.vue b/src/components/VnSelectProvince.vue index 606799e50..9fcbef11e 100644 --- a/src/components/VnSelectProvince.vue +++ b/src/components/VnSelectProvince.vue @@ -1,5 +1,5 @@ + diff --git a/src/components/common/VnProgressModal.vue b/src/components/common/VnProgressModal.vue index cfd948d5f..23fb8ae70 100644 --- a/src/components/common/VnProgressModal.vue +++ b/src/components/common/VnProgressModal.vue @@ -9,10 +9,6 @@ const $props = defineProps({ type: Number, //Progress value (1.0 > x > 0.0) required: true, }, - showDialog: { - type: Boolean, - required: true, - }, cancelled: { type: Boolean, required: false, @@ -24,30 +20,22 @@ const emit = defineEmits(['cancel', 'close']); const dialogRef = ref(null); -const _showDialog = computed({ - get: () => $props.showDialog, - set: (value) => { - if (value) dialogRef.value.show(); - }, +const showDialog = defineModel('showDialog', { + type: Boolean, + default: false, }); const _progress = computed(() => $props.progress); - const progressLabel = computed(() => `${Math.round($props.progress * 100)}%`); - -const cancel = () => { - dialogRef.value.hide(); - emit('cancel'); -};