enhancement #I7HPAN onError方法增加Exception入参

This commit is contained in:
everywhere.z 2023-07-02 20:30:37 +08:00
parent 0b54beacbe
commit 6457587e7f
11 changed files with 24 additions and 20 deletions

View File

@ -112,7 +112,7 @@ public abstract class NodeComponent {
// 执行失败后回调方法
// 这里要注意失败方法本身抛出错误只打出堆栈往外抛出的还是主要的异常
try {
self.onError();
self.onError(e);
}
catch (Exception ex) {
String errMsg = StrUtil.format("component[{}] onError method happens exception", this.getDisplayName());
@ -151,7 +151,7 @@ public abstract class NodeComponent {
// 如果需要在成功后回调某一个方法请覆盖这个方法
}
public void onError() throws Exception {
public void onError(Exception e) throws Exception {
// 如果需要在抛错后回调某一段逻辑请覆盖这个方法
}

View File

@ -2,10 +2,7 @@ package com.yomahub.liteflow.core.proxy;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Tuple;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.*;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.annotation.LiteflowRetry;
import com.yomahub.liteflow.core.NodeComponent;
@ -198,19 +195,24 @@ public class ComponentProxy {
.orElse(null);
// 如果被代理的对象里有此标注标的方法则调用此被代理的对象里的方法如果没有则调用父类里的方法
// 进行检查检查被代理的bean里是否有且仅有NodeComponent这个类型的参数
boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1
&& Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class);
// 进行检查检查被代理的bean里是否第一个参数为NodeComponent这个类型的
boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length > 0
&& liteFlowMethodBean.getMethod().getParameterTypes()[0].equals(NodeComponent.class);
if (!checkFlag) {
String errMsg = StrUtil.format(
"Method[{}.{}] must have NodeComponent parameter(and only one parameter)",
"Method[{}.{}] must have NodeComponent parameter(first parameter is NodeComponent)",
bean.getClass().getName(), liteFlowMethodBean.getMethod().getName());
LOG.error(errMsg);
throw new ComponentMethodDefineErrorException(errMsg);
}
try {
return liteFlowMethodBean.getMethod().invoke(bean, proxy);
if (args.length > 0){
Object[] wrapArgs = ArrayUtil.insert(args, 0, proxy);
return liteFlowMethodBean.getMethod().invoke(bean, wrapArgs);
}else{
return liteFlowMethodBean.getMethod().invoke(bean, proxy);
}
}
catch (Exception e) {
InvocationTargetException targetEx = (InvocationTargetException) e;

View File

@ -23,7 +23,7 @@ public class DCmp {
}
@LiteflowMethod(LiteFlowMethodEnum.ON_ERROR)
public void onError(NodeComponent bindCmp) throws Exception {
public void onError(NodeComponent bindCmp, Exception e) throws Exception {
DefaultContext context = bindCmp.getFirstContextBean();
context.setData("error", "error:" + bindCmp.getNodeId());
}

View File

@ -19,7 +19,7 @@ public class DCmp extends NodeComponent {
}
@Override
public void onError() throws Exception {
public void onError(Exception e) throws Exception {
DefaultContext context = this.getFirstContextBean();
context.setData("error", "error:" + this.getNodeId());
}

View File

@ -19,7 +19,7 @@ public class ECmp extends NodeComponent {
}
@Override
public void onError() throws Exception {
public void onError(Exception e) throws Exception {
DefaultContext context = this.getFirstContextBean();
context.setData("error", "error:" + this.getNodeId());
throw new IllegalAccessException("错误事件回调本身抛出异常");

View File

@ -21,7 +21,7 @@ public class DCmp extends NodeComponent {
}
@Override
public void onError() throws Exception {
public void onError(Exception e) throws Exception {
DefaultContext context = this.getFirstContextBean();
context.setData("error", "error:" + this.getNodeId());
}

View File

@ -21,7 +21,7 @@ public class ECmp extends NodeComponent {
}
@Override
public void onError() throws Exception {
public void onError(Exception e) throws Exception {
DefaultContext context = this.getFirstContextBean();
context.setData("error", "error:" + this.getNodeId());
throw new IllegalAccessException("错误事件回调本身抛出异常");

View File

@ -9,6 +9,7 @@ package com.yomahub.liteflow.test.event.cmp;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.DefaultContext;
import com.yomahub.liteflow.slot.Slot;
import org.springframework.stereotype.Component;
@Component("d")
@ -21,7 +22,8 @@ public class DCmp extends NodeComponent {
}
@Override
public void onError() throws Exception {
public void onError(Exception e) throws Exception {
Slot slot = this.getSlot();
DefaultContext context = this.getFirstContextBean();
context.setData("error", "error:" + this.getNodeId());
}

View File

@ -21,7 +21,7 @@ public class ECmp extends NodeComponent {
}
@Override
public void onError() throws Exception {
public void onError(Exception e) throws Exception {
DefaultContext context = this.getFirstContextBean();
context.setData("error", "error:" + this.getNodeId());
throw new IllegalAccessException("错误事件回调本身抛出异常");

View File

@ -21,7 +21,7 @@ public class DCmp extends NodeComponent {
}
@Override
public void onError() throws Exception {
public void onError(Exception e) throws Exception {
DefaultContext context = this.getFirstContextBean();
context.setData("error", "error:" + this.getNodeId());
}

View File

@ -21,7 +21,7 @@ public class ECmp extends NodeComponent {
}
@Override
public void onError() throws Exception {
public void onError(Exception e) throws Exception {
DefaultContext context = this.getFirstContextBean();
context.setData("error", "error:" + this.getNodeId());
throw new IllegalAccessException("错误事件回调本身抛出异常");