diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCommandContext.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCommandContext.java index 5af132216..2d9e867d0 100644 --- a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCommandContext.java +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCommandContext.java @@ -1,6 +1,7 @@ package cn.axzo.workflow.core.engine.cmd; import cn.axzo.workflow.core.common.exception.WorkflowEngineException; +import com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException; import org.apache.ibatis.exceptions.PersistenceException; import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.api.FlowableOptimisticLockingException; @@ -10,7 +11,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.StringUtils; +import java.sql.SQLIntegrityConstraintViolationException; import java.util.Arrays; +import java.util.Objects; /** * 对 CommandContext 中的 WorkflowEngineException 进行日志降级 @@ -42,13 +45,24 @@ public class CustomCommandContext extends CommandContext { LOGGER.info("Error while closing command context", exception); } else if (exception instanceof WorkflowEngineException) { LOGGER.warn("Workflow error while closing command context", exception); - } else if (exception instanceof PersistenceException && - StringUtils.hasText(exception.getMessage()) && - Arrays.stream(PERSISTENCE_EXCEPTION_WARN_MESSAGE).anyMatch(m -> exception.getMessage().contains(m))) { - LOGGER.warn("persistence error while closing command context", exception); + } else if (exception instanceof PersistenceException) { + Throwable rootCause = getRootCause(exception); + if (rootCause instanceof MySQLTransactionRollbackException) { + LOGGER.warn("MySQL transaction rollback exception : {}", rootCause.getMessage(), rootCause); + } if (rootCause instanceof SQLIntegrityConstraintViolationException){ + LOGGER.warn("SQL constraint violation exception : {}", rootCause.getMessage(), rootCause); + } else { + LOGGER.warn("persistence error while closing command context:{}", exception.getMessage(), exception); + } } else { LOGGER.error("Error while closing command context", exception); - } } + + private Throwable getRootCause(Throwable throwable) { + while (Objects.nonNull(throwable.getCause())) { + throwable = throwable.getCause(); + } + return throwable; + } }