forked from verdnatura/salix-front
106 lines
3.8 KiB
JavaScript
106 lines
3.8 KiB
JavaScript
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 opts = {
|
|
actions: [
|
|
{
|
|
icon: 'support_agent',
|
|
color: 'primary',
|
|
dense: true,
|
|
flat: false,
|
|
round: true,
|
|
handler: async () => {
|
|
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,
|
|
},
|
|
}
|
|
);
|
|
},
|
|
},
|
|
],
|
|
};
|
|
notify(message ?? 'globals.error', 'negative', 'error', opts);
|
|
};
|
|
});
|