forked from verdnatura/salix-front
feat: refs #8039 notify error unify
This commit is contained in:
parent
52981953f7
commit
9780fe596f
|
@ -40,37 +40,7 @@ const onResponse = (response) => {
|
|||
const onResponseError = (error) => {
|
||||
stateQuery.remove(error.config);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (session.isLoggedIn() && response?.status === 401) {
|
||||
if (session.isLoggedIn() && error.response?.status === 401) {
|
||||
session.destroy(false);
|
||||
const hash = window.location.hash;
|
||||
const url = hash.slice(1);
|
||||
|
@ -79,8 +49,6 @@ const onResponseError = (error) => {
|
|||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
if (!(error instanceof CanceledError)) notify(message, 'negative');
|
||||
|
||||
return Promise.reject(error);
|
||||
};
|
||||
|
||||
|
|
|
@ -10,8 +10,39 @@ export default boot(({ app }) => {
|
|||
app.mixin(qFormMixin);
|
||||
app.mixin(mainShortcutMixin);
|
||||
app.directive('shortcut', keyShortcut);
|
||||
app.config.errorHandler = function (err) {
|
||||
console.error(err);
|
||||
if (!(err instanceof CanceledError)) notify('globals.error', 'negative', 'error');
|
||||
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 CanceledError) return;
|
||||
|
||||
notify(message ?? 'globals.error', 'negative', 'error');
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue