mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-23 22:38:10 +08:00
enhancement #I5IOC5 LiteFlowResponse增加一个errorCode
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.yomahub.liteflow.test.exception;
|
||||
|
||||
import com.yomahub.liteflow.exception.LiteFlowException;
|
||||
|
||||
/**
|
||||
* 用户自定义带状态码的异常
|
||||
*/
|
||||
public class CustomStatefulException extends LiteFlowException {
|
||||
public CustomStatefulException(int code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test.exception;
|
||||
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
import com.yomahub.liteflow.exception.ChainNotFoundException;
|
||||
import com.yomahub.liteflow.exception.LiteFlowException;
|
||||
import com.yomahub.liteflow.exception.NoSwitchTargetNodeException;
|
||||
import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
@@ -50,4 +51,21 @@ public class Exception2ELSpringTest extends BaseTest {
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
throw response.getCause();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeCustomStatefulException() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception");
|
||||
Assert.assertFalse(response.isSuccess());
|
||||
Assert.assertEquals(300, response.getCode());
|
||||
Assert.assertNotNull(response.getCause());
|
||||
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
|
||||
Assert.assertNotNull(response.getSlot());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotInvokeCustomStatefulException() {
|
||||
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
|
||||
Assert.assertTrue(response.isSuccess());
|
||||
Assert.assertEquals(0, response.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.exception.cmp;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.test.exception.CustomStatefulException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("f")
|
||||
public class FCmp extends NodeComponent {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FCmp.class);
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
String str = this.getRequestData();
|
||||
if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) {
|
||||
throw new CustomStatefulException(300, "chain execute custom stateful execption");
|
||||
}
|
||||
LOG.info("Fcomp executed!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* <p>Title: liteflow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2020/4/1
|
||||
*/
|
||||
package com.yomahub.liteflow.test.exception.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("g")
|
||||
public class GCmp extends NodeComponent {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GCmp.class);
|
||||
|
||||
@Override
|
||||
public void process() {
|
||||
LOG.info("Gcomp executed!");
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,8 @@
|
||||
SWITCH(e).to(b, c);
|
||||
</chain>
|
||||
|
||||
<chain name="chain6">
|
||||
THEN(f, g);
|
||||
</chain>
|
||||
|
||||
</flow>
|
||||
Reference in New Issue
Block a user