fix:ProcessController.preCheck的context为空指针的问题

pull/6/head
SamLee 3 years ago
parent 1ddece43fe
commit b658333300

@ -0,0 +1,39 @@
package com.java3y.austin.support.exception;
import com.java3y.austin.common.enums.RespStatusEnum;
import com.java3y.austin.support.pipeline.ProcessContext;
/**
* @author SamLee
* @since 2022-03-29
*/
public class ProcessException extends RuntimeException {
/**
*
*/
private final ProcessContext processContext;
public ProcessException(ProcessContext processContext) {
super();
this.processContext = processContext;
}
public ProcessException(ProcessContext processContext, Throwable cause) {
super(cause);
this.processContext = processContext;
}
@Override
public String getMessage() {
if (this.processContext != null) {
return this.processContext.getResponse().getMsg();
} else {
return RespStatusEnum.CONTEXT_IS_NULL.getMsg();
}
}
public ProcessContext getProcessContext() {
return processContext;
}
}

@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.java3y.austin.common.enums.RespStatusEnum;
import com.java3y.austin.common.vo.BasicResultVO;
import com.java3y.austin.support.exception.ProcessException;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@ -34,10 +35,13 @@ public class ProcessController {
*/
public ProcessContext process(ProcessContext context) {
try {
/**
*
*/
if (!preCheck(context)) {
preCheck(context);
} catch(ProcessException e) {
context = e.getProcessContext();
return context;
}
@ -55,36 +59,40 @@ public class ProcessController {
}
private Boolean preCheck(ProcessContext context) {
/**
*
* @param context
* @throws ProcessException
*/
private void preCheck(ProcessContext context) throws ProcessException {
// 上下文
if (context == null) {
context = new ProcessContext();
context.setResponse(BasicResultVO.fail(RespStatusEnum.CONTEXT_IS_NULL));
return false;
throw new ProcessException(context);
}
// 业务代码
String businessCode = context.getCode();
if (StrUtil.isBlank(businessCode)) {
context.setResponse(BasicResultVO.fail(RespStatusEnum.BUSINESS_CODE_IS_NULL));
return false;
throw new ProcessException(context);
}
// 执行模板
ProcessTemplate processTemplate = templateConfig.get(businessCode);
if (processTemplate == null) {
context.setResponse(BasicResultVO.fail(RespStatusEnum.PROCESS_TEMPLATE_IS_NULL));
return false;
throw new ProcessException(context);
}
// 执行模板列表
List<BusinessProcess> processList = processTemplate.getProcessList();
if (CollUtil.isEmpty(processList)) {
context.setResponse(BasicResultVO.fail(RespStatusEnum.PROCESS_LIST_IS_NULL));
return false;
throw new ProcessException(context);
}
return true;
}

Loading…
Cancel
Save