From 4bb4362d236254810af088e864d03ddbeb516363 Mon Sep 17 00:00:00 2001 From: MakerLab <47223013+MakerLab-Dev@users.noreply.github.com> Date: Thu, 30 Jan 2020 20:45:39 +0100 Subject: [PATCH 1/3] Removed unnecessary notification Removed unnecessary notification as the improved error handler will show it --- resources/assets/js/store/modules/auth/actions.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/resources/assets/js/store/modules/auth/actions.js b/resources/assets/js/store/modules/auth/actions.js index f92ba4f0..05bc5d86 100644 --- a/resources/assets/js/store/modules/auth/actions.js +++ b/resources/assets/js/store/modules/auth/actions.js @@ -21,13 +21,6 @@ export const login = ({ commit, dispatch, state }, data) => { window.toastr['success']('Login Successful') resolve(response) }).catch(err => { - if (err.response.data.error === 'invalid_credentials') { - window.toastr['error']('Invalid Credentials') - } else { - // Something happened in setting up the request that triggered an Error - console.log('Error', err.message) - } - commit(types.AUTH_ERROR, err.response) Ls.remove('auth.token') reject(err) From 1c19be85c324cf3b0006ce51f88ad77a91710ce9 Mon Sep 17 00:00:00 2001 From: MakerLab-Dev Date: Thu, 30 Jan 2020 20:47:51 +0100 Subject: [PATCH 2/3] Improved error handling --- resources/assets/js/bootstrap.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/resources/assets/js/bootstrap.js b/resources/assets/js/bootstrap.js index 81a69b2e..c15095f8 100644 --- a/resources/assets/js/bootstrap.js +++ b/resources/assets/js/bootstrap.js @@ -88,17 +88,27 @@ window.axios.interceptors.request.use(function (config) { global.axios.interceptors.response.use(undefined, function (err) { // Do something with request error - return new Promise((resolve, reject) => { + if (!err.response) { + window.toastr['error']('Network error: Please check your internet connection or wait until servers are back online') + console.log('Network error: Please check your internet connection.') + } else { console.log(err.response) - if (err.response.data.error === 'invalid_credentials') { - window.toastr['error']('Invalid Credentials') - } if (err.response.data && (err.response.statusText === 'Unauthorized' || err.response.data === ' Unauthorized.')) { + // Unauthorized and log out + window.toastr['error']((err.response.data.message) ? err.response.data.message : 'Unauthorized') store.dispatch('auth/logout', true) + } else if (err.response.data.errors) { + // Show a notification per error + const errors = JSON.parse(JSON.stringify(err.response.data.errors)) + for (const i in errors) { + window.toastr['error'](errors[i]) + } } else { - throw err + // Unknown error + window.toastr['error']((err.response.data.message) ? err.response.data.message : 'Unknown error occurred') } - }) + } + return Promise.reject(err) }) /** From af189b15b658d8aca3ee7ba5298600bdcc151367 Mon Sep 17 00:00:00 2001 From: MakerLab-Dev Date: Thu, 30 Jan 2020 20:48:16 +0100 Subject: [PATCH 3/3] Small fix --- resources/assets/js/views/auth/Login.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/assets/js/views/auth/Login.vue b/resources/assets/js/views/auth/Login.vue index 71f11758..8b59e5a6 100644 --- a/resources/assets/js/views/auth/Login.vue +++ b/resources/assets/js/views/auth/Login.vue @@ -46,7 +46,7 @@ - {{ $t('login.login') }} + {{ $t('login.login') }}