Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve client error handling for notification template API #304

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public NotificationTemplate getNotificationTemplate(String notificationChannel,
String error = String
.format(IdentityMgtConstants.ErrorMessages.ERROR_CODE_NO_TEMPLATE_FOUND.getMessage(),
templateType, locale, tenantDomain);
throw new NotificationTemplateManagerServerException(
throw new NotificationTemplateManagerClientException(
IdentityMgtConstants.ErrorMessages.ERROR_CODE_NO_TEMPLATE_FOUND.getCode(), error);
} else {
if (log.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ public void addNotificationTemplateType(String notificationChannel, String displ
try {
if (templatePersistenceManager
.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);
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 NotificationTemplateManagerClientException(code, message);
}
templatePersistenceManager.addNotificationTemplateType(displayName, notificationChannel,
tenantDomain);
Expand All @@ -108,19 +111,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 All @@ -144,7 +134,7 @@ public void deleteNotificationTemplateType(String notificationChannel, String te
String message = String.format(
TemplateMgtConstants.ErrorMessages.ERROR_CODE_SYSTEM_RESOURCE_DELETION_NOT_ALLOWED.getMessage(),
"System template types are not eligible for deletion.");
throw new NotificationTemplateManagerServerException(code, message);
throw new NotificationTemplateManagerClientException(code, message);
}

try {
Expand Down Expand Up @@ -311,7 +301,7 @@ public NotificationTemplate getNotificationTemplate(String notificationChannel,
String errorMessage = String
.format(TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_NOT_FOUND.getMessage(),
templateType, tenantDomain);
throw new NotificationTemplateManagerServerException(code, errorMessage);
throw new NotificationTemplateManagerClientException(code, errorMessage);
} else {
if (log.isDebugEnabled()) {
String message = String
Expand Down Expand Up @@ -366,7 +356,7 @@ public NotificationTemplate getSystemNotificationTemplate(String notificationCha
String errorMessage = String
.format(TemplateMgtConstants.ErrorMessages.ERROR_CODE_SYSTEM_TEMPLATE_NOT_FOUND.getMessage(),
templateType);
throw new NotificationTemplateManagerServerException(code, errorMessage);
throw new NotificationTemplateManagerClientException(code, errorMessage);
} else {
if (log.isDebugEnabled()) {
String message = String
Expand Down Expand Up @@ -419,7 +409,7 @@ public void addNotificationTemplate(NotificationTemplate notificationTemplate, S
String message = String.format(
TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_ALREADY_EXISTS.getMessage(), displayName,
tenantDomain);
throw new NotificationTemplateManagerServerException(code, message);
throw new NotificationTemplateManagerClientException(code, message);
}
try {
userDefinedTemplatePersistenceManager.addOrUpdateNotificationTemplate(notificationTemplate, applicationUuid,
Expand Down Expand Up @@ -469,7 +459,7 @@ public void updateNotificationTemplate(NotificationTemplate notificationTemplate
String message = String.format(
TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_NOT_FOUND.getMessage(), displayName,
tenantDomain);
throw new NotificationTemplateManagerServerException(code, message);
throw new NotificationTemplateManagerClientException(code, message);
}
try {
userDefinedTemplatePersistenceManager.addOrUpdateNotificationTemplate(notificationTemplate, applicationUuid,
Expand Down Expand Up @@ -693,7 +683,7 @@ private String getDefaultNotificationLocale(String notificationChannel) {
}

private void verifySystemTemplateTypeExists(String templateType, String notificationChannel)
throws NotificationTemplateManagerServerException {
throws NotificationTemplateManagerClientException, NotificationTemplateManagerServerException {

if (!systemTemplatePersistenceManager.isNotificationTemplateTypeExists(templateType, notificationChannel,
null)) {
Expand All @@ -703,12 +693,12 @@ private void verifySystemTemplateTypeExists(String templateType, String notifica
String message = String.format(
TemplateMgtConstants.ErrorMessages.ERROR_CODE_SYSTEM_TEMPLATE_TYPE_NOT_FOUND.getMessage(),
templateType);
throw new NotificationTemplateManagerServerException(code, message);
throw new NotificationTemplateManagerClientException(code, message);
}
}

private void verifyTemplateTypeExists(String templateType, String notificationChannel, String tenantDomain)
throws NotificationTemplateManagerServerException {
throws NotificationTemplateManagerServerException, NotificationTemplateManagerClientException {

if (!templatePersistenceManager.isNotificationTemplateTypeExists(templateType, notificationChannel,
tenantDomain)) {
Expand All @@ -718,7 +708,7 @@ private void verifyTemplateTypeExists(String templateType, String notificationCh
String message = String.format(
TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_TYPE_NOT_FOUND.getMessage(),
templateType, tenantDomain);
throw new NotificationTemplateManagerServerException(code, message);
throw new NotificationTemplateManagerClientException(code, message);
}
}
}
Loading