From 97fdb0acbe76843afaa78fd2254cf1e12564a604 Mon Sep 17 00:00:00 2001 From: "S.S.S. Dissanayake" Date: Fri, 1 May 2026 17:51:32 +0530 Subject: [PATCH] Fix #19300: Avoid unnecessary error logging for existing email templates --- .../v1/core/ServerEmailTemplatesService.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java index 79028b5f25..b2a3da1b2f 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java @@ -263,8 +263,18 @@ public SimpleEmailTemplate addEmailTemplate(String templateTypeId, EmailTemplate throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_ALREADY_EXISTS); } } catch (I18nEmailMgtException e) { - throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_ADDING_EMAIL_TEMPLATE); + // Check if the error is due to the template already existing (Conflict) + if (Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) { + // We only log this as a DEBUG message to keep Carbon logs clean + if (log.isDebugEnabled()) { + log.debug("Email template already exists: " + emailTemplateWithID.getId(), e); + } + } else { + // Log as an actual error only if it's a real server-side failure + log.error("Error occurred while adding email template", e); } + throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_ADDING_EMAIL_TEMPLATE); + } } /**