From b2c9308b80fc8c3d9301c158df6514703b943779 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 25 Oct 2019 18:24:52 +0200 Subject: [PATCH] Implement try/catch error handling in invite module --- src/store/modules/invites.js | 27 +++++++++++++++++++++++---- src/views/invites/index.vue | 13 ++----------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/store/modules/invites.js b/src/store/modules/invites.js index bdf43ce3..730b25d1 100644 --- a/src/store/modules/invites.js +++ b/src/store/modules/invites.js @@ -1,4 +1,6 @@ import { generateInviteToken, inviteViaEmail, listInviteTokens, revokeToken } from '@/api/invites' +import { Message } from 'element-ui' +import i18n from '@/lang' const invites = { state: { @@ -25,18 +27,35 @@ const invites = { commit('SET_LOADING', false) }, async GenerateInviteToken({ commit, dispatch, getters }, { maxUse, expiresAt }) { - const { data } = await generateInviteToken(maxUse, expiresAt, getters.authHost, getters.token) - commit('SET_NEW_TOKEN', { token: data.token, maxUse: data.max_use, expiresAt: data.expires_at }) + try { + const { data } = await generateInviteToken(maxUse, expiresAt, getters.authHost, getters.token) + commit('SET_NEW_TOKEN', { token: data.token, maxUse: data.max_use, expiresAt: data.expires_at }) + } catch (_e) { + return + } dispatch('FetchInviteTokens') }, async InviteUserViaEmail({ commit, dispatch, getters }, { email, name }) { - await inviteViaEmail(email, name, getters.authHost, getters.token) + try { + await inviteViaEmail(email, name, getters.authHost, getters.token) + } catch (_e) { + return + } + Message({ + message: i18n.t('invites.emailSent'), + type: 'success', + duration: 5 * 1000 + }) }, RemoveNewToken({ commit }) { commit('SET_NEW_TOKEN', {}) }, async RevokeToken({ commit, dispatch, getters }, token) { - await revokeToken(token, getters.authHost, getters.token) + try { + await revokeToken(token, getters.authHost, getters.token) + } catch (_e) { + return + } dispatch('FetchInviteTokens') } } diff --git a/src/views/invites/index.vue b/src/views/invites/index.vue index 783e897a..e8ca75fd 100644 --- a/src/views/invites/index.vue +++ b/src/views/invites/index.vue @@ -192,17 +192,8 @@ export default { async inviteUserViaEmail() { this.$refs['inviteUserForm'].validate(async(valid) => { if (valid) { - try { - await this.$store.dispatch('InviteUserViaEmail', this.$data.inviteUserForm) - } catch (_e) { - return - } finally { - this.closeDialogWindow() - } - this.$message({ - type: 'success', - message: this.$t('invites.emailSent') - }) + await this.$store.dispatch('InviteUserViaEmail', this.$data.inviteUserForm) + this.closeDialogWindow() } else { this.$message({ type: 'error',