You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/07/13 09:52:19 UTC

[GitHub] [dubbo] AlbumenJ commented on issue #10314: 怎么对 Dubbo的业务异常进行统一封装

AlbumenJ commented on issue #10314:
URL: https://github.com/apache/dubbo/issues/10314#issuecomment-1183013779

   You can try this.
   
   ```
   @Activate(group = CommonConstants.PROVIDER)
   public class ResultConvertFilter implements Filter, BaseFilter.Listener {
       @Override
       public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
           return invoker.invoke(invocation);
       }
   
       @Override
       public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
           if (appResponse.hasException()) {
               // reset value
               appResponse.setValue(new Object());
               appResponse.setException(null);
           } else {
               Object originValue = appResponse.getValue();
               if (originValue instanceof Exception) {
                   // reset value
                   appResponse.setValue(new Object());
               }
           }
       }
   
       @Override
       public void onError(Throwable t, Invoker<?> invoker, Invocation invocation) {
           // framework error, can be ignore
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org