From ac60784f95db4f15a558e24e613842d921e9979c Mon Sep 17 00:00:00 2001 From: iamsivin Date: Fri, 3 Apr 2026 00:12:58 +0530 Subject: [PATCH] chore: Review fix --- .../conversation/contact/ContactInfo.vue | 16 ++++++++++++---- app/javascript/shared/helpers/CustomErrors.js | 11 ++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue b/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue index 675f9ec28..d8213828f 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/contact/ContactInfo.vue @@ -215,10 +215,18 @@ export default { ); } catch (error) { if (error instanceof DuplicateContactException) { - if (error.data.includes('email')) { - useAlert(this.$t('CONTACT_FORM.FORM.EMAIL_ADDRESS.DUPLICATE')); - } else if (error.data.includes('phone_number')) { - useAlert(this.$t('CONTACT_FORM.FORM.PHONE_NUMBER.DUPLICATE')); + const detail = error.contactErrorDetail; + if (detail) { + useAlert(detail); + } else { + const invalidAttrs = Array.isArray(error.data) ? error.data : []; + if (invalidAttrs.includes('email')) { + useAlert(this.$t('CONTACT_FORM.FORM.EMAIL_ADDRESS.DUPLICATE')); + } else if (invalidAttrs.includes('phone_number')) { + useAlert(this.$t('CONTACT_FORM.FORM.PHONE_NUMBER.DUPLICATE')); + } else { + useAlert(this.$t('CONTACT_FORM.ERROR_MESSAGE')); + } } } else if (error instanceof ExceptionWithMessage) { useAlert(error.data); diff --git a/app/javascript/shared/helpers/CustomErrors.js b/app/javascript/shared/helpers/CustomErrors.js index 4f31eb291..ef5947189 100644 --- a/app/javascript/shared/helpers/CustomErrors.js +++ b/app/javascript/shared/helpers/CustomErrors.js @@ -1,10 +1,19 @@ /* eslint-disable max-classes-per-file */ export class DuplicateContactException extends Error { + static DEFAULT_MESSAGE = 'DUPLICATE_CONTACT'; + constructor(data) { - super('DUPLICATE_CONTACT'); + super(DuplicateContactException.DEFAULT_MESSAGE); this.data = data; this.name = 'DuplicateContactException'; } + + /** Server or client may assign `message` after construction; otherwise still DEFAULT_MESSAGE. */ + get contactErrorDetail() { + return this.message === DuplicateContactException.DEFAULT_MESSAGE + ? null + : this.message; + } } export class ExceptionWithMessage extends Error { constructor(data) {