dromara/liteflow

FlowExecutor 异常优化

taotao365s opened this issue · 0 comments

private Slot doExecute(String chainId, Object param, String requestId, Class<?>[] contextBeanClazzArray, Object[] contextBeanArray,
			Integer slotIndex, InnerChainTypeEnum innerChainType) {
		//....

		Chain chain = null;
		try {
			chain = FlowBus.getChain(chainId);

			if (ObjectUtil.isNull(chain)) {
				String errorMsg = StrUtil.format("couldn't find chain with the id[{}]", chainId);
				throw new ChainNotFoundException(errorMsg);
			}
			// 执行chain
			chain.execute(slotIndex);
		}
		catch (ChainEndException e) {
			if (ObjectUtil.isNotNull(chain)) {
				String warnMsg = StrUtil.format("chain[{}] execute end on slot[{}]", chain.getChainId(), slotIndex);
				LOG.warn(warnMsg);
			}
		}
		catch (Exception e) {
			if (ObjectUtil.isNotNull(chain)) {
				String errMsg = StrUtil.format("chain[{}] execute error on slot[{}]", chain.getChainId(), slotIndex);
				if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
					LOG.error(errMsg, e);
				}
				else {
					LOG.error(errMsg);
				}
			}
			else {
				if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
					LOG.error(e.getMessage(), e);
				}
				else {
					LOG.error(e.getMessage());
				}
			}

			// 如果是正常流程需要把异常设置到slot的exception属性里
			// 如果是隐式流程,则需要设置到隐式流程的exception属性里
			if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
				slot.setException(e);
			}
			else {
				slot.setSubException(chainId, e);
			}
		}
		finally {
			if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
				slot.printStep();
				DataBus.releaseSlot(slotIndex);
				LFLoggerManager.removeRequestId();
			}
		}

catch (Exception e) 能否增加配置,异常部分继续往上抛?在不同公司或项目中,往往会有各种各样的异常