fix(errors): snackbars for 502 and notification not found errors should have timeout (#10394)

This commit is contained in:
Matteo Pagliazzi 2018-05-25 12:30:43 +02:00 committed by GitHub
parent fc62db147f
commit eaf0c62e16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -303,12 +303,6 @@ export default {
if (error.response.status >= 400) {
this.checkForBannedUser(error);
// Check for conditions to reset the user auth
const invalidUserMessage = [this.$t('invalidCredentials'), 'Missing authentication headers.'];
if (invalidUserMessage.indexOf(error.response.data) !== -1) {
this.$store.dispatch('auth:logout');
}
// Don't show errors from getting user details. These users have delete their account,
// but their chat message still exists.
let configExists = Boolean(error.response) && Boolean(error.response.config);
@ -321,11 +315,27 @@ export default {
const errorData = error.response.data;
const errorMessage = errorData.message || errorData;
// Check for conditions to reset the user auth
const invalidUserMessage = [this.$t('invalidCredentials'), 'Missing authentication headers.'];
if (invalidUserMessage.indexOf(errorMessage) !== -1) {
this.$store.dispatch('auth:logout');
}
// Most server errors should return is click to dismiss errors, with some exceptions
let snackbarTimeout = false;
if (error.response.status === 502) snackbarTimeout = true;
const notificationNotFoundMessage = [
this.$t('messageNotificationNotFound'),
this.$t('messageNotificationNotFound', 'en'),
];
if (notificationNotFoundMessage.indexOf(errorMessage) !== -1) snackbarTimeout = true;
this.$store.dispatch('snackbars:add', {
title: 'Habitica',
text: errorMessage,
type: 'error',
timeout: false,
timeout: snackbarTimeout,
});
}