From eaf0c62e162a1a8cb2555c346d6d4470a7ca999c Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Fri, 25 May 2018 12:30:43 +0200 Subject: [PATCH] fix(errors): snackbars for 502 and notification not found errors should have timeout (#10394) --- website/client/app.vue | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/website/client/app.vue b/website/client/app.vue index 8471bb1adb..1cc5d88f34 100644 --- a/website/client/app.vue +++ b/website/client/app.vue @@ -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, }); }