diff --git a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/NotificationTemplateManagerImpl.java b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/NotificationTemplateManagerImpl.java index 70aaf6c7..93b2dadc 100644 --- a/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/NotificationTemplateManagerImpl.java +++ b/components/email-mgt/org.wso2.carbon.email.mgt/src/main/java/org/wso2/carbon/email/mgt/NotificationTemplateManagerImpl.java @@ -100,10 +100,14 @@ public void addNotificationTemplateType(String notificationChannel, String displ try { if (unifiedTemplatePersistenceManager .isNotificationTemplateTypeExists(displayName, notificationChannel, tenantDomain)) { - // This error is caught in the catch block below to generate the - // NotificationTemplateManagerServerException. - throw new NotificationTemplateManagerInternalException( - TemplateMgtConstants.ErrorCodes.TEMPLATE_TYPE_ALREADY_EXISTS, StringUtils.EMPTY); + // Throwing error due to duplicate template type. + String code = I18nEmailUtil.prependOperationScenarioToErrorCode( + TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_TYPE_ALREADY_EXISTS.getCode(), + TemplateMgtConstants.ErrorScenarios.NOTIFICATION_TEMPLATE_MANAGER); + String message = String.format( + TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_TYPE_ALREADY_EXISTS.getMessage(), + displayName, tenantDomain); + throw new NotificationTemplateManagerServerException(code, message); } unifiedTemplatePersistenceManager.addNotificationTemplateType(displayName, notificationChannel, tenantDomain); @@ -115,19 +119,6 @@ public void addNotificationTemplateType(String notificationChannel, String displ TemplateMgtConstants.ErrorMessages.ERROR_CODE_ERROR_ADDING_TEMPLATE.getMessage(), displayName, tenantDomain); throw new NotificationTemplateManagerException(code, message, e); - } catch (NotificationTemplateManagerInternalException e) { - if (TemplateMgtConstants.ErrorCodes.TEMPLATE_TYPE_ALREADY_EXISTS.equals(e.getErrorCode())) { - String code = I18nEmailUtil.prependOperationScenarioToErrorCode( - TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_TYPE_ALREADY_EXISTS.getCode(), - TemplateMgtConstants.ErrorScenarios.NOTIFICATION_TEMPLATE_MANAGER); - String message = String.format( - TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_TYPE_ALREADY_EXISTS.getMessage(), - displayName, tenantDomain); - throw new NotificationTemplateManagerServerException(code, message, e); - } - if (log.isDebugEnabled()) { - log.debug("Error when adding template type : " + displayName + " to tenant : " + tenantDomain, e); - } } }