2024-03-21 13:56:39 +00:00
|
|
|
import { boot } from 'quasar/wrappers';
|
|
|
|
import qFormMixin from './qformMixin';
|
2024-08-28 12:04:48 +00:00
|
|
|
import keyShortcut from './keyShortcut';
|
2024-09-18 12:48:15 +00:00
|
|
|
import useNotify from 'src/composables/useNotify.js';
|
2024-10-21 11:23:45 +00:00
|
|
|
import { CanceledError } from 'axios';
|
2024-10-22 11:34:20 +00:00
|
|
|
|
2024-09-18 12:48:15 +00:00
|
|
|
const { notify } = useNotify();
|
2024-03-21 13:56:39 +00:00
|
|
|
|
|
|
|
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-22 11:34:20 +00:00
|
|
|
if (error instanceof CanceledError) {
|
|
|
|
const env = process.env.NODE_ENV;
|
|
|
|
if (env && env !== 'development') return;
|
|
|
|
message = 'Duplicate request';
|
|
|
|
}
|
2024-10-21 11:33:12 +00:00
|
|
|
|
|
|
|
notify(message ?? 'globals.error', 'negative', 'error');
|
2024-09-18 12:48:15 +00:00
|
|
|
};
|
2024-03-21 13:56:39 +00:00
|
|
|
});
|