import { ref } from 'vue'; import axios from 'axios'; import { boot } from 'quasar/wrappers'; import qFormMixin from './qformMixin'; import keyShortcut from './keyShortcut'; import { i18n } from './i18n'; import useNotify from 'src/composables/useNotify.js'; import { useStateQueryStore } from 'src/stores/useStateQueryStore'; import VnInput from 'src/components/common/VnInput.vue'; import { useVnConfirm } from 'src/composables/useVnConfirm'; const { notify } = useNotify(); const stateQuery = useStateQueryStore(); const { openConfirmationModal } = useVnConfirm(); export default boot(({ app }) => { app.mixin(qFormMixin); app.directive('shortcut', keyShortcut); 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 axios.CanceledError) { const env = process.env.NODE_ENV; if (env && env !== 'development') return; message = 'Duplicate request'; } // Convey to Alex or Juan... const additionalData = { frontPath: stateQuery.route.name, backError: { config: error.config, data: error, }, httpRequest: error.request.response, }; const isErrorPrivaleges = response?.code == 'ACCESS_DENIED'; const opts = { actions: [ { icon: 'support_agent', color: 'primary', dense: true, flat: false, round: true, noDismiss: isErrorPrivaleges, handler: async () => { if (isErrorPrivaleges) { // Create message and send to support console.log('QUIERO ACCEDER!!!'); } else { const reason = ref(); openConfirmationModal( i18n.global.t('globals.sendCau'), false, async () => { await axios.post('OsTickets/send-to-support', { reason: reason.value, additionalData, }); }, null, { component: VnInput, props: { modelValue: reason, 'onUpdate:modelValue': (val) => (reason.value = val), label: i18n.global.t('globals.ExplainReason'), class: 'full-width', required: true, }, } ); } }, }, ], }; notify(message ?? 'globals.error', 'negative', 'error', opts); }; });