Merge branch 'refs/heads/master' into REQ-2393

This commit is contained in:
wangli 2024-04-25 09:38:51 +08:00
commit 83f4ba8a1a
5 changed files with 36 additions and 9 deletions

View File

@ -5,8 +5,14 @@ import cn.axzo.framework.autoconfigure.web.exception.handler.AbstractExceptionAp
import cn.axzo.framework.domain.web.code.IRespCode;
import cn.axzo.framework.domain.web.code.RespCode;
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import cn.axzo.workflow.server.common.config.property.WorkflowProperties;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import static org.springframework.http.HttpStatus.OK;
/**
* 基于 Flowable 框架在业务功能开发过程中,抛出的异常处理器
*
@ -15,12 +21,20 @@ import org.springframework.stereotype.Component;
*/
@Component
public class WorkflowExceptionResultHandlerAdvice extends AbstractExceptionApiResultHandler<WorkflowEngineException> {
@Resource
private WorkflowProperties workflowProperties;
public WorkflowExceptionResultHandlerAdvice(RespErrorCodeMappingProperties properties) {
super(properties);
}
@Override
protected IRespCode decode(WorkflowEngineException ex, IRespCode fallbackCode) {
List<String> filterExceptionCodes = workflowProperties.getFilterExceptionCode();
if (filterExceptionCodes.contains(ex.getCode())) {
return new RespCode(String.valueOf(OK.value()), ex.getMessage());
}
return new RespCode(ex.getCode(), ex.getMessage());
}
}

View File

@ -2,6 +2,7 @@ package cn.axzo.workflow.server.common.annotation;
import cn.axzo.workflow.server.common.util.DingTalkUtils;
import cn.azxo.framework.common.utils.LogUtil;
import lombok.extern.slf4j.Slf4j;
import static cn.axzo.workflow.server.common.aspectj.RepeatSubmitAspect.argsArrayToString;
@ -12,6 +13,7 @@ import static cn.axzo.workflow.server.common.aspectj.RepeatSubmitAspect.argsArra
* @author wangli
* @since 2024/4/2 10:36
*/
@Slf4j
public enum ReporterType {
/**
@ -19,7 +21,7 @@ public enum ReporterType {
*/
ONLY_DING_TALK {
@Override
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e) {
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e, Boolean downgrade) {
if (sendDingTalk) {
DingTalkUtils.sendDingTalk(profile, title, argsArrayToString(args), e);
}
@ -31,8 +33,12 @@ public enum ReporterType {
*/
ONLY_LOG {
@Override
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e) {
LogUtil.error(LogUtil.ErrorType.ERROR_BUSINESS, shortString, e.getMessage(), e);
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e, Boolean downgrade) {
if (downgrade) {
log.warn("ER: {}", e.getMessage());
} else {
LogUtil.error(LogUtil.ErrorType.ERROR_BUSINESS, shortString, e.getMessage(), e);
}
}
},
/**
@ -40,11 +46,15 @@ public enum ReporterType {
*/
BOTH {
@Override
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e) {
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e, Boolean downgrade) {
if (sendDingTalk) {
DingTalkUtils.sendDingTalk(profile, title, argsArrayToString(args), e);
}
LogUtil.error(LogUtil.ErrorType.ERROR_BUSINESS, shortString, e.getMessage(), e);
if (downgrade) {
log.warn("ER: {}", e.getMessage());
} else {
LogUtil.error(LogUtil.ErrorType.ERROR_BUSINESS, shortString, e.getMessage(), e);
}
}
};
@ -56,6 +66,6 @@ public enum ReporterType {
* @param shortString 用于日志输出的关键信息
* @param e 异常对象
*/
public abstract void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e);
public abstract void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e, Boolean downgrade);
}

View File

@ -114,8 +114,9 @@ public class ErrorReportAspect implements Ordered {
log.info("ErrorReportAspect 记录异常信息: {}", e.getMessage());
EnvConfig[] envConfigs = errorReporter.envConfig();
for (EnvConfig envConfig : envConfigs) {
if (Arrays.asList(envConfig.profiles()).contains(profile) && !workflowProperties.getFilterOperations().contains(operation.summary())) {
envConfig.type().executeAction(profile, operation.summary(), sendDingTalk, joinPoint.getArgs(), joinPoint.getSignature().toShortString(), e);
if (Arrays.asList(envConfig.profiles()).contains(profile)) {
envConfig.type().executeAction(profile, operation.summary(), sendDingTalk, joinPoint.getArgs(), joinPoint.getSignature().toShortString(), e,
!workflowProperties.getFilterOperations().contains(operation.summary()));
}
}
}

View File

@ -25,4 +25,6 @@ public class WorkflowProperties {
private List<String> filterOperations = new ArrayList<>();
private List<String> filterExceptionCode = new ArrayList<>();
}

View File

@ -30,7 +30,7 @@ public class ErrorReporterEventListener implements BpmnAsyncExecutionErrorEventL
} else if (Lists.newArrayList("live", "master").contains(profile)) {
reporterType = ReporterType.ONLY_LOG;
}
reporterType.executeAction(profile, "异步任务执行异常, 剩余重试次数:" + jobInfo.getRetries(), sendDingTalk, new Object[]{jobInfo}, "act_ru_job", throwable);
reporterType.executeAction(profile, "异步任务执行异常, 剩余重试次数:" + jobInfo.getRetries(), sendDingTalk, new Object[]{jobInfo}, "act_ru_job", throwable, false);
}
@Override