From e1bf8d156ebb1eeebfeaf59dfbaa051347de37be Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 29 Mar 2021 16:52:45 +0900 Subject: [PATCH] Update error handling --- frontend/components/auth/FormLogin.vue | 19 +++++++++---------- frontend/store/auth.js | 10 +++++++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/frontend/components/auth/FormLogin.vue b/frontend/components/auth/FormLogin.vue index 40a9c23b..12f70b5a 100644 --- a/frontend/components/auth/FormLogin.vue +++ b/frontend/components/auth/FormLogin.vue @@ -68,17 +68,16 @@ export default Vue.extend({ }, methods: { - tryLogin() { - this.login({ - username: this.username, - password: this.password - }) - .then(() => { - this.$router.push(this.localePath('/projects')) - }) - .catch(() => { - this.showError = true + async tryLogin() { + try { + await this.login({ + username: this.username, + password: this.password }) + this.$router.push(this.localePath('/projects')) + } catch { + this.showError = true + } } } }) diff --git a/frontend/store/auth.js b/frontend/store/auth.js index a2136acb..6ac1a3e4 100644 --- a/frontend/store/auth.js +++ b/frontend/store/auth.js @@ -25,9 +25,13 @@ export const getters = { } export const actions = { - authenticateUser({ commit }, authData) { - this.$services.auth.login(authData.username, authData.password) - commit('setAuthenticated', true) + async authenticateUser({ commit }, authData) { + try { + await this.$services.auth.login(authData.username, authData.password) + commit('setAuthenticated', true) + } catch(error) { + throw new Error('The credential is invalid') + } }, async initAuth({ commit }) { try {