diff --git a/app/javascript/dashboard/routes/dashboard/settings/labels/AddLabel.vue b/app/javascript/dashboard/routes/dashboard/settings/labels/AddLabel.vue index cbf0ca3bf..9ff1697ed 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/labels/AddLabel.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/labels/AddLabel.vue @@ -93,21 +93,21 @@ export default { } return color; }, - addLabel() { - this.$store - .dispatch('labels/create', { + async addLabel() { + try { + await this.$store.dispatch('labels/create', { color: this.color, description: this.description, title: this.title, show_on_sidebar: this.showOnSidebar, - }) - .then(() => { - this.showAlert(this.$t('LABEL_MGMT.ADD.API.SUCCESS_MESSAGE')); - this.onClose(); - }) - .catch(() => { - this.showAlert(this.$t('LABEL_MGMT.ADD.API.ERROR_MESSAGE')); }); + this.showAlert(this.$t('LABEL_MGMT.ADD.API.SUCCESS_MESSAGE')); + this.onClose(); + } catch (error) { + const errorMessage = + error.message || this.$t('LABEL_MGMT.ADD.API.ERROR_MESSAGE'); + this.showAlert(errorMessage); + } }, }, }; diff --git a/app/javascript/dashboard/store/modules/labels.js b/app/javascript/dashboard/store/modules/labels.js index 4183c28ed..f597212a3 100644 --- a/app/javascript/dashboard/store/modules/labels.js +++ b/app/javascript/dashboard/store/modules/labels.js @@ -45,7 +45,8 @@ export const actions = { const response = await LabelsAPI.create(cannedObj); commit(types.ADD_LABEL, response.data); } catch (error) { - throw new Error(error); + const errorMessage = error?.response?.data?.message; + throw new Error(errorMessage); } finally { commit(types.SET_LABEL_UI_FLAG, { isCreating: false }); }