enhancement #I7HPAN onError方法增加Exception入参
This commit is contained in:
parent
0b54beacbe
commit
6457587e7f
|
@ -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 {
|
||||
// 如果需要在抛错后回调某一段逻辑,请覆盖这个方法
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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("错误事件回调本身抛出异常");
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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("错误事件回调本身抛出异常");
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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("错误事件回调本身抛出异常");
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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("错误事件回调本身抛出异常");
|
||||
|
|
Loading…
Reference in New Issue