Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
RushanNanayakkara committed Oct 21, 2024
1 parent b828356 commit 3df47ce
Showing 1 changed file with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
}

Expand Down

0 comments on commit 3df47ce

Please sign in to comment.