Skip to content

怎么对 Dubbo的业务异常进行统一封装 #10314

@wcc1433

Description

@wcc1433

想定义一个 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;
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions