-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Closed
Description
想定义一个 provider端的 filter,将业务异常封装之后返回 {"code": 500, "msg": "xxx"}给 consumer端。但是在网上找到的都是通过 spring aop的方式进行处理的。
下面是我自己的一个示例(不知道怎么封装成 result):
@activate(group = {CommonConstants.PROVIDER}, order = -2)
public class ExceptionFilter implements Filter {
@OverRide
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
Result result = invoker.invoke(invocation);
if (result.getException() instanceof BaseException) {
// 判断抛出的异常是否为业务异常
BaseException exception = (BaseException) result.getException();
result = ???
} else if (result.getException() instanceof Exception) {
result = ???
}
return result;
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels