From c4b13ebb9f526e469d134c9f8262e302c53c6619 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 25 Oct 2019 18:32:47 +0200 Subject: [PATCH] Move try/catch error handling from view file to relays module --- src/store/modules/relays.js | 20 ++++++++++++++++---- src/views/settings/components/Relays.vue | 16 ++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/store/modules/relays.js b/src/store/modules/relays.js index 6353569e..3a0d15cc 100644 --- a/src/store/modules/relays.js +++ b/src/store/modules/relays.js @@ -28,15 +28,27 @@ const relays = { commit('SET_RELAYS', response.data.relays) commit('SET_LOADING', false) }, - async AddRelay({ commit, getters }, relay) { + async AddRelay({ commit, dispatch, getters }, relay) { commit('ADD_RELAY', relay) - await addRelay(relay, getters.authHost, getters.token) + try { + await addRelay(relay, getters.authHost, getters.token) + } catch (_e) { + return + } finally { + dispatch('FetchRelays') + } }, - async DeleteRelay({ commit, getters }, relay) { + async DeleteRelay({ commit, dispatch, getters }, relay) { commit('DELETE_RELAY', relay) - await deleteRelay(relay, getters.authHost, getters.token) + try { + await deleteRelay(relay, getters.authHost, getters.token) + } catch (_e) { + return + } finally { + dispatch('FetchRelays') + } } } } diff --git a/src/views/settings/components/Relays.vue b/src/views/settings/components/Relays.vue index ef9264b4..18db6f5b 100644 --- a/src/views/settings/components/Relays.vue +++ b/src/views/settings/components/Relays.vue @@ -52,22 +52,10 @@ export default { }, methods: { followRelay() { - try { - this.$store.dispatch('AddRelay', this.newRelay) - } catch (_e) { - return - } finally { - this.$store.dispatch('FetchRelays') - } + this.$store.dispatch('AddRelay', this.newRelay) }, deleteRelay(relay) { - try { - this.$store.dispatch('DeleteRelay', relay) - } catch (_e) { - return - } finally { - this.$store.dispatch('FetchRelays') - } + this.$store.dispatch('DeleteRelay', relay) } } }