diff --git a/app/javascript/dashboard/i18n/locale/en/agentMgmt.json b/app/javascript/dashboard/i18n/locale/en/agentMgmt.json index 56e77e5a5..769947b33 100644 --- a/app/javascript/dashboard/i18n/locale/en/agentMgmt.json +++ b/app/javascript/dashboard/i18n/locale/en/agentMgmt.json @@ -45,6 +45,7 @@ }, "API": { "SUCCESS_MESSAGE": "Agent added successfully", + "EXIST_MESSAGE": "Agent email already in use, Please try another email address", "ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later" } }, diff --git a/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue b/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue index b10af87bc..728d753d9 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue @@ -128,7 +128,11 @@ export default { this.showAlert(this.$t('AGENT_MGMT.ADD.API.SUCCESS_MESSAGE')); this.onClose(); } catch (error) { - this.showAlert(this.$t('AGENT_MGMT.ADD.API.ERROR_MESSAGE')); + if (error.response.status === 422) { + this.showAlert(this.$t('AGENT_MGMT.ADD.API.EXIST_MESSAGE')); + } else { + this.showAlert(this.$t('AGENT_MGMT.ADD.API.ERROR_MESSAGE')); + } } }, }, diff --git a/app/javascript/dashboard/store/modules/agents.js b/app/javascript/dashboard/store/modules/agents.js index 7c6a82c4b..6807a6c45 100644 --- a/app/javascript/dashboard/store/modules/agents.js +++ b/app/javascript/dashboard/store/modules/agents.js @@ -43,7 +43,7 @@ export const actions = { commit(types.default.SET_AGENT_CREATING_STATUS, false); } catch (error) { commit(types.default.SET_AGENT_CREATING_STATUS, false); - throw new Error(error); + throw error; } }, update: async ({ commit }, { id, ...agentParams }) => { diff --git a/app/javascript/dashboard/store/modules/specs/agents/actions.spec.js b/app/javascript/dashboard/store/modules/specs/agents/actions.spec.js index 152c1d780..54d55bacf 100644 --- a/app/javascript/dashboard/store/modules/specs/agents/actions.spec.js +++ b/app/javascript/dashboard/store/modules/specs/agents/actions.spec.js @@ -40,7 +40,9 @@ describe('#actions', () => { }); it('sends correct actions if API is error', async () => { axios.post.mockRejectedValue({ message: 'Incorrect header' }); - await expect(actions.create({ commit })).rejects.toThrow(Error); + await expect(actions.create({ commit })).rejects.toEqual({ + message: 'Incorrect header', + }); expect(commit.mock.calls).toEqual([ [types.default.SET_AGENT_CREATING_STATUS, true], [types.default.SET_AGENT_CREATING_STATUS, false],