跳到主要内容

ActionAfter

介绍

本篇介绍如何扩展 ActionAfter 接口,将异常信息携带到请求端。

业务框架的异常机制,默认只保存错误码,不会保存错误码对应的异常信息。 如果想把异常信息携带到请求端,可以通过扩展 ActionAfter 来实现。

public class DebugActionAfter implements ActionAfter {
ActionAfter actionAfter = new DefaultActionAfter();

@Override
public void execute(final FlowContext flowContext) {
final ResponseMessage response = flowContext.getResponse();
if (response.hasError()) {
// get error info. cn: 得到异常消息
String msg = flowContext.option(FlowAttr.msgException);
// carry exception information to the requesting end.
// cn: 将异常信息携带到请求端
response.setValidatorMsg(msg);
}

actionAfter.execute(flowContext);
}
}

public class YourLogicServer extends AbstractBrokerClientStartup {
@Override
public BarSkeleton createBarSkeleton() {
BarSkeletonBuilder builder = ...

// setting ActionAfter
builder.setActionAfter(new DebugActionAfter());
return builder.build();
}
}