From 6f6bb9182342a9658dfb4ea904af974ce4d2b894 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Wed, 29 Sep 2021 13:00:08 +0530 Subject: [PATCH] fix: Add meaningful alert error message if file upload fails (#3093) Co-authored-by: Muhsin Keloth --- .../dashboard/components/widgets/conversation/ReplyBox.vue | 5 ++++- app/javascript/dashboard/i18n/locale/en/conversation.json | 1 + .../dashboard/store/modules/conversations/actions.js | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue index e06cdb239..ff831281b 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue @@ -347,7 +347,10 @@ export default { await this.$store.dispatch('sendMessage', messagePayload); this.$emit('scrollToMessage'); } catch (error) { - // Error + const errorMessage = + error?.response?.data?.error || + this.$t('CONVERSATION.MESSAGE_ERROR'); + this.showAlert(errorMessage); } this.hideEmojiPicker(); } diff --git a/app/javascript/dashboard/i18n/locale/en/conversation.json b/app/javascript/dashboard/i18n/locale/en/conversation.json index 42a25e897..d9f4eeba4 100644 --- a/app/javascript/dashboard/i18n/locale/en/conversation.json +++ b/app/javascript/dashboard/i18n/locale/en/conversation.json @@ -84,6 +84,7 @@ "CHANGE_AGENT": "Conversation Assignee changed", "CHANGE_TEAM": "Conversation team changed", "FILE_SIZE_LIMIT": "File exceeds the {MAXIMUM_FILE_UPLOAD_SIZE} attachment limit", + "MESSAGE_ERROR": "Unable to send this message, please try again later", "SENT_BY": "Sent by:", "ASSIGNMENT": { "SELECT_AGENT": "Select Agent", diff --git a/app/javascript/dashboard/store/modules/conversations/actions.js b/app/javascript/dashboard/store/modules/conversations/actions.js index 0415d8724..2af6f8130 100644 --- a/app/javascript/dashboard/store/modules/conversations/actions.js +++ b/app/javascript/dashboard/store/modules/conversations/actions.js @@ -155,6 +155,7 @@ const actions = { }, sendMessage: async ({ commit }, data) => { + // eslint-disable-next-line no-useless-catch try { const pendingMessage = createPendingMessage(data); commit(types.default.ADD_MESSAGE, pendingMessage); @@ -164,7 +165,7 @@ const actions = { status: MESSAGE_STATUS.SENT, }); } catch (error) { - // Handle error + throw error; } },