enhancement #I5IOC5 LiteFlowResponse增加一个errorCode

This commit is contained in:
everywhere.z 2022-07-26 23:24:01 +08:00
parent 4bd63e8925
commit fee14a6a22
29 changed files with 44 additions and 57 deletions

View File

@ -209,8 +209,7 @@ public class FlowExecutor {
private LiteflowResponse execute2Resp(String chainId, Object param, Class<?>[] contextBeanClazzArray,
Integer slotIndex, boolean isInnerChain) {
Slot slot = doExecute(chainId, param, contextBeanClazzArray, slotIndex, isInnerChain);
LiteflowResponse response = new LiteflowResponse(slot);
return response;
return new LiteflowResponse(slot);
}
private Slot doExecute(String chainId, Object param, Class<?>[] contextBeanClazzArray, Integer slotIndex,

View File

@ -4,16 +4,15 @@ package com.yomahub.liteflow.exception;
/**
* LiteFlow架内部逻辑发生错误抛出的异常
* (自定义此异常方便开发者在做全局异常处理时分辨异常类型)
*
* @author zendwang
*
* @since 2.8.3
*/
public class LiteFlowException extends RuntimeException {
private static final long serialVersionUID = 1L;
/** 异常状态码 */
private int code;
private String code;
/**
* 构建一个异常
@ -29,7 +28,7 @@ public class LiteFlowException extends RuntimeException {
* @param code 异常状态码
* @param message 异常描述信息
*/
public LiteFlowException(int code, String message) {
public LiteFlowException(String code, String message) {
super(message);
this.code = code;
}
@ -43,16 +42,6 @@ public class LiteFlowException extends RuntimeException {
super(cause);
}
/**
* 构建一个异常
* @param code 异常状态码
* @param cause 异常对象
*/
public LiteFlowException(int code, Throwable cause) {
super(cause);
this.code = code;
}
/**
* 构建一个异常
*
@ -69,7 +58,7 @@ public class LiteFlowException extends RuntimeException {
* @param message 异常信息
* @param cause 异常对象
*/
public LiteFlowException(int code, String message, Throwable cause) {
public LiteFlowException(String code, String message, Throwable cause) {
super(message, cause);
this.code = code;
}
@ -77,7 +66,7 @@ public class LiteFlowException extends RuntimeException {
/**
* @return 获得异常状态码
*/
public int getCode() {
public String getCode() {
return code;
}
}

View File

@ -19,7 +19,7 @@ public class LiteflowResponse implements Serializable {
private boolean success;
private int code;
private String code;
private String message;
@ -35,11 +35,9 @@ public class LiteflowResponse implements Serializable {
this.success = false;
this.cause = slot.getException();
this.message = this.cause.getMessage();
this.code = this.cause instanceof LiteFlowException ? ((LiteFlowException)this.cause).getCode() : -1;
this.code = this.cause instanceof LiteFlowException ? ((LiteFlowException)this.cause).getCode() : null;
} else {
this.success = true;
this.code = 0;
this.message = "";
}
this.slot = slot;
}
@ -60,11 +58,11 @@ public class LiteflowResponse implements Serializable {
this.message = message;
}
public int getCode() {
public String getCode() {
return code;
}
public void setCode(int code) {
public void setCode(String code) {
this.code = code;
}

View File

@ -122,7 +122,7 @@ public class Slot{
}
}
public <T> void setChainReqData(String chainId, T t) {
public synchronized <T> void setChainReqData(String chainId, T t) {
String key = CHAIN_REQ_PREFIX + chainId;
if (hasMetaData(key)){
Queue<Object> queue = (Queue<Object>) metaDataMap.get(key);

View File

@ -6,7 +6,7 @@ import com.yomahub.liteflow.exception.LiteFlowException;
* 用户自定义带状态码的异常
*/
public class CustomStatefulException extends LiteFlowException {
public CustomStatefulException(int code, String message) {
public CustomStatefulException(String code, String message) {
super(code, message);
}
}

View File

@ -61,7 +61,7 @@ public class Exception2ELDeclSpringBootTest extends BaseTest {
public void testInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(300, response.getCode());
Assert.assertEquals("300", response.getCode());
Assert.assertNotNull(response.getCause());
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
Assert.assertNotNull(response.getSlot());
@ -71,6 +71,6 @@ public class Exception2ELDeclSpringBootTest extends BaseTest {
public void testNotInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(0, response.getCode());
Assert.assertNull(response.getCode());
}
}

View File

@ -27,7 +27,7 @@ public class FCmp {
public void process(NodeComponent bindCmp) {
String str = bindCmp.getRequestData();
if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) {
throw new CustomStatefulException(300, "chain execute custom stateful execption");
throw new CustomStatefulException("300", "chain execute custom stateful execption");
}
LOG.info("Fcomp executed!");
}

View File

@ -6,7 +6,7 @@ import com.yomahub.liteflow.exception.LiteFlowException;
* 用户自定义带状态码的异常
*/
public class CustomStatefulException extends LiteFlowException {
public CustomStatefulException(int code, String message) {
public CustomStatefulException(String code, String message) {
super(code, message);
}
}

View File

@ -69,7 +69,7 @@ public class Exception2Test extends BaseTest {
public void testInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(300, response.getCode());
Assert.assertEquals("300", response.getCode());
Assert.assertNotNull(response.getCause());
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
Assert.assertNotNull(response.getSlot());
@ -79,6 +79,6 @@ public class Exception2Test extends BaseTest {
public void testNotInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(0, response.getCode());
Assert.assertNull(response.getCode());
}
}

View File

@ -21,7 +21,7 @@ public class FCmp extends NodeComponent {
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");
throw new CustomStatefulException("300", "chain execute custom stateful execption");
}
LOG.info("Fcomp executed!");
}

View File

@ -6,7 +6,7 @@ import com.yomahub.liteflow.exception.LiteFlowException;
* 用户自定义带状态码的异常
*/
public class CustomStatefulException extends LiteFlowException {
public CustomStatefulException(int code, String message) {
public CustomStatefulException(String code, String message) {
super(code, message);
}
}

View File

@ -69,7 +69,7 @@ public class Exception2ELSpringBootTest extends BaseTest {
public void testInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(300, response.getCode());
Assert.assertEquals("300", response.getCode());
Assert.assertNotNull(response.getCause());
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
Assert.assertNotNull(response.getSlot());
@ -79,6 +79,6 @@ public class Exception2ELSpringBootTest extends BaseTest {
public void testNotInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(0, response.getCode());
Assert.assertNull(response.getCode());
}
}

View File

@ -23,7 +23,7 @@ public class FCmp extends NodeComponent {
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");
throw new CustomStatefulException("300", "chain execute custom stateful execption");
}
LOG.info("Fcomp executed!");
}

View File

@ -10,6 +10,7 @@ import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

View File

@ -6,7 +6,7 @@ import com.yomahub.liteflow.exception.LiteFlowException;
* 用户自定义带状态码的异常
*/
public class CustomStatefulException extends LiteFlowException {
public CustomStatefulException(int code, String message) {
public CustomStatefulException(String code, String message) {
super(code, message);
}
}

View File

@ -56,7 +56,7 @@ public class Exception2ELSpringTest extends BaseTest {
public void testInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(300, response.getCode());
Assert.assertEquals("300", response.getCode());
Assert.assertNotNull(response.getCause());
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
Assert.assertNotNull(response.getSlot());
@ -66,6 +66,6 @@ public class Exception2ELSpringTest extends BaseTest {
public void testNotInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(0, response.getCode());
Assert.assertNull(response.getCode());
}
}

View File

@ -23,7 +23,7 @@ public class FCmp extends NodeComponent {
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");
throw new CustomStatefulException("300", "chain execute custom stateful execption");
}
LOG.info("Fcomp executed!");
}

View File

@ -6,7 +6,7 @@ import com.yomahub.liteflow.exception.LiteFlowException;
* 用户自定义带状态码的异常
*/
public class CustomStatefulException extends LiteFlowException {
public CustomStatefulException(int code, String message) {
public CustomStatefulException(String code, String message) {
super(code, message);
}
}

View File

@ -73,7 +73,7 @@ public class Exception2SpringBootTest extends BaseTest {
public void testInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(300, response.getCode());
Assert.assertEquals("300", response.getCode());
Assert.assertNotNull(response.getCause());
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
Assert.assertNotNull(response.getSlot());
@ -83,6 +83,6 @@ public class Exception2SpringBootTest extends BaseTest {
public void testNotInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(0, response.getCode());
Assert.assertNull(response.getCode());
}
}

View File

@ -27,7 +27,7 @@ public class FCmp {
public void process(NodeComponent bindCmp) {
String str = bindCmp.getRequestData();
if(StrUtil.isNotBlank(str) && str.equals("custom-stateful-exception")) {
throw new CustomStatefulException(300, "chain execute custom stateful execption");
throw new CustomStatefulException("300", "chain execute custom stateful execption");
}
LOG.info("Fcomp executed!");
}

View File

@ -6,7 +6,7 @@ import com.yomahub.liteflow.exception.LiteFlowException;
* 用户自定义带状态码的异常
*/
public class CustomStatefulException extends LiteFlowException {
public CustomStatefulException(int code, String message) {
public CustomStatefulException(String code, String message) {
super(code, message);
}
}

View File

@ -66,7 +66,7 @@ public class Exception2Test extends BaseTest {
public void testInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(300, response.getCode());
Assert.assertEquals("300", response.getCode());
Assert.assertNotNull(response.getCause());
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
Assert.assertNotNull(response.getSlot());
@ -76,6 +76,6 @@ public class Exception2Test extends BaseTest {
public void testNotInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(0, response.getCode());
Assert.assertNull(response.getCode());
}
}

View File

@ -21,7 +21,7 @@ public class FCmp extends NodeComponent {
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");
throw new CustomStatefulException("300", "chain execute custom stateful execption");
}
LOG.info("Fcomp executed!");
}

View File

@ -6,7 +6,7 @@ import com.yomahub.liteflow.exception.LiteFlowException;
* 用户自定义带状态码的异常
*/
public class CustomStatefulException extends LiteFlowException {
public CustomStatefulException(int code, String message) {
public CustomStatefulException(String code, String message) {
super(code, message);
}
}

View File

@ -76,7 +76,7 @@ public class Exception2SpringBootTest extends BaseTest {
public void testInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(300, response.getCode());
Assert.assertEquals("300", response.getCode());
Assert.assertNotNull(response.getCause());
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
Assert.assertNotNull(response.getSlot());
@ -86,6 +86,6 @@ public class Exception2SpringBootTest extends BaseTest {
public void testNotInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(0, response.getCode());
Assert.assertNull(response.getCode());
}
}

View File

@ -23,7 +23,7 @@ public class FCmp extends NodeComponent {
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");
throw new CustomStatefulException("300", "chain execute custom stateful execption");
}
LOG.info("Fcomp executed!");
}

View File

@ -6,7 +6,7 @@ import com.yomahub.liteflow.exception.LiteFlowException;
* 用户自定义带状态码的异常
*/
public class CustomStatefulException extends LiteFlowException {
public CustomStatefulException(int code, String message) {
public CustomStatefulException(String code, String message) {
super(code, message);
}
}

View File

@ -67,7 +67,7 @@ public class Exception2SpringTest extends BaseTest {
public void testInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "custom-stateful-exception");
Assert.assertFalse(response.isSuccess());
Assert.assertEquals(300, response.getCode());
Assert.assertEquals("300", response.getCode());
Assert.assertNotNull(response.getCause());
Assert.assertTrue(response.getCause() instanceof LiteFlowException);
Assert.assertNotNull(response.getSlot());
@ -77,6 +77,6 @@ public class Exception2SpringTest extends BaseTest {
public void testNotInvokeCustomStatefulException() {
LiteflowResponse response = flowExecutor.execute2Resp("chain6", "test");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals(0, response.getCode());
Assert.assertNull(response.getCode());
}
}

View File

@ -23,7 +23,7 @@ public class FCmp extends NodeComponent {
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");
throw new CustomStatefulException("300", "chain execute custom stateful execption");
}
LOG.info("Fcomp executed!");
}