Move try/catch error handling from view file to relays module

This commit is contained in:
Angelina Filippova 2019-10-25 18:32:47 +02:00
parent b2c9308b80
commit c4b13ebb9f
2 changed files with 18 additions and 18 deletions

View file

@ -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')
}
}
}
}

View file

@ -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)
}
}
}