use try/catch

Signed-off-by: Jakob <jakob.roehrl@web.de>
This commit is contained in:
Jakob
2019-10-09 12:45:33 +02:00
parent 71e7c98fd6
commit 1c2c700593
3 changed files with 18 additions and 28 deletions

View File

@@ -136,14 +136,13 @@ export default {
this.loading = true this.loading = true
try { try {
const newBoard = await this.$store.dispatch('cloneBoard', this.board) const newBoard = await this.$store.dispatch('cloneBoard', this.board)
this.loading = false this.loading = false
const route = this.routeTo const route = this.routeTo
route.params.id = newBoard.id route.params.id = newBoard.id
this.$router.push(route) this.$router.push(route)
} } catch (e) {
catch {
OC.Notification.showTemporary(t('deck', 'An error occurred')) OC.Notification.showTemporary(t('deck', 'An error occurred'))
console.error(e)
} }
}, },
icon: 'icon-clone', icon: 'icon-clone',

View File

@@ -135,19 +135,13 @@ export class BoardApi {
}) })
} }
cloneBoard(board) { async cloneBoard(board) {
return axios.post(this.url(`/boards/${board.id}/clone`)) try {
.then( let response = await axios.post(this.url(`/boards/${board.id}/clone`))
(response) => { return response.data
return Promise.resolve(response.data) } catch (err) {
}, return err
(err) => {
return Promise.reject(err)
} }
)
.catch((err) => {
return Promise.reject(err)
})
} }
// Label API Calls // Label API Calls

View File

@@ -280,17 +280,14 @@ export default new Vuex.Store({
commit('addBoard', board) commit('addBoard', board)
}) })
}, },
cloneBoard({ commit }, boardData) { async cloneBoard({ commit }, boardData) {
return new Promise((resolve, reject) => { try {
apiClient.cloneBoard(boardData) let newBoard = await apiClient.cloneBoard(boardData)
.then((board) => { commit('cloneBoard', newBoard)
commit('cloneBoard', board) return newBoard
resolve(board) } catch (err) {
}) return err
.catch((err) => { }
return reject(err)
})
})
}, },
removeBoard({ commit }, board) { removeBoard({ commit }, board) {
commit('removeBoard', board) commit('removeBoard', board)