0
0
Fork 0
salix-front-mindshore-fork2/src/boot/quasar.js

106 lines
3.8 KiB
JavaScript
Raw Normal View History

2024-10-30 12:55:51 +00:00
import { ref } from 'vue';
import axios from 'axios';
import { boot } from 'quasar/wrappers';
import qFormMixin from './qformMixin';
2024-08-28 12:04:48 +00:00
import keyShortcut from './keyShortcut';
2024-10-30 12:55:51 +00:00
import { i18n } from './i18n';
2024-09-18 12:48:15 +00:00
import useNotify from 'src/composables/useNotify.js';
2024-10-30 12:55:51 +00:00
import { useStateQueryStore } from 'src/stores/useStateQueryStore';
import VnInput from 'src/components/common/VnInput.vue';
import { useVnConfirm } from 'src/composables/useVnConfirm';
2024-09-18 12:48:15 +00:00
const { notify } = useNotify();
2024-10-30 12:55:51 +00:00
const stateQuery = useStateQueryStore();
const { openConfirmationModal } = useVnConfirm();
export default boot(({ app }) => {
app.mixin(qFormMixin);
2024-08-28 12:04:48 +00:00
app.directive('shortcut', keyShortcut);
2024-10-21 11:33:12 +00:00
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);
2024-10-30 12:55:51 +00:00
if (error instanceof axios.CanceledError) {
const env = process.env.NODE_ENV;
if (env && env !== 'development') return;
message = 'Duplicate request';
}
2024-10-30 12:55:51 +00:00
// Convey to Alex or Juan...
const additionalData = {
frontPath: stateQuery.route.name,
backError: {
config: error.config,
data: error,
},
httpRequest: error.request.response,
};
const opts = {
actions: [
{
icon: 'support_agent',
color: 'primary',
dense: true,
flat: false,
round: true,
handler: async () => {
2024-11-13 12:11:02 +00:00
const reason = ref(
response.data.error.code == 'ACCESS_DENIED'
? i18n.global.t('cau.askPrivileges')
: ''
);
openConfirmationModal(
i18n.global.t('cau.title'),
i18n.global.t('cau.subtitle'),
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('cau.inputLabel'),
class: 'full-width',
required: true,
2024-10-30 12:55:51 +00:00
},
2024-11-13 12:11:02 +00:00
}
);
2024-10-30 12:55:51 +00:00
},
},
],
};
notify(message ?? 'globals.error', 'negative', 'error', opts);
2024-09-18 12:48:15 +00:00
};
});