0
0
Fork 0

feat: refs #8039 notify error unify

This commit is contained in:
Alex Moreno 2024-10-21 13:33:12 +02:00
parent 52981953f7
commit 9780fe596f
2 changed files with 35 additions and 36 deletions

View File

@ -40,37 +40,7 @@ const onResponse = (response) => {
const onResponseError = (error) => { const onResponseError = (error) => {
stateQuery.remove(error.config); stateQuery.remove(error.config);
let message = ''; if (session.isLoggedIn() && error.response?.status === 401) {
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;
}
if (session.isLoggedIn() && response?.status === 401) {
session.destroy(false); session.destroy(false);
const hash = window.location.hash; const hash = window.location.hash;
const url = hash.slice(1); const url = hash.slice(1);
@ -79,8 +49,6 @@ const onResponseError = (error) => {
return Promise.reject(error); return Promise.reject(error);
} }
if (!(error instanceof CanceledError)) notify(message, 'negative');
return Promise.reject(error); return Promise.reject(error);
}; };

View File

@ -10,8 +10,39 @@ export default boot(({ app }) => {
app.mixin(qFormMixin); app.mixin(qFormMixin);
app.mixin(mainShortcutMixin); app.mixin(mainShortcutMixin);
app.directive('shortcut', keyShortcut); app.directive('shortcut', keyShortcut);
app.config.errorHandler = function (err) { app.config.errorHandler = (error) => {
console.error(err); let message;
if (!(err instanceof CanceledError)) notify('globals.error', 'negative', 'error'); 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) return;
notify(message ?? 'globals.error', 'negative', 'error');
}; };
}); });