This is an automated email from the ASF dual-hosted git repository.

victory pushed a commit to branch 2.7.3-release
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/2.7.3-release by this push:
     new b5408b7  support handle of exception from onResponse or onError (#4401)
b5408b7 is described below

commit b5408b752631644d5934971f4ba11d165c776536
Author: ken.lj <[email protected]>
AuthorDate: Fri Jun 28 15:39:56 2019 +0800

    support handle of exception from onResponse or onError (#4401)
    
    fix #4401
---
 .../java/org/apache/dubbo/rpc/AsyncRpcResult.java   |  9 +++++----
 .../dubbo/rpc/protocol/ProtocolFilterWrapper.java   | 21 ++++++---------------
 2 files changed, 11 insertions(+), 19 deletions(-)

diff --git 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
index f002ae7..343cf03 100644
--- 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
+++ 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java
@@ -138,14 +138,15 @@ public class AsyncRpcResult extends AbstractResult {
 
     @Override
     public Result whenCompleteWithContext(BiConsumer<Result, Throwable> fn) {
-        this.whenComplete((v, t) -> {
+        CompletableFuture<Result> future = this.whenComplete((v, t) -> {
             beforeContext.accept(v, t);
             fn.accept(v, t);
             afterContext.accept(v, t);
         });
-        // You may need to return a new Result instance representing the next 
async stage,
-        // like thenApply will return a new CompletableFuture.
-        return this;
+
+        AsyncRpcResult nextStage = new AsyncRpcResult(this);
+        nextStage.subscribeTo(future);
+        return nextStage;
     }
 
     public void subscribeTo(CompletableFuture<?> future) {
diff --git 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java
 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java
index 441718d..a7039a1 100644
--- 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java
+++ 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/ProtocolFilterWrapper.java
@@ -156,33 +156,24 @@ public class ProtocolFilterWrapper implements Protocol {
         public Result invoke(Invocation invocation) throws RpcException {
             Result asyncResult = filterInvoker.invoke(invocation);
 
-            asyncResult.whenCompleteWithContext((r, t) -> {
+            asyncResult = asyncResult.whenCompleteWithContext((r, t) -> {
                 for (int i = filters.size() - 1; i >= 0; i--) {
                     Filter filter = filters.get(i);
                     // onResponse callback
                     if (filter instanceof ListenableFilter) {
                         Filter.Listener listener = ((ListenableFilter) 
filter).listener();
                         if (listener != null) {
-                            try {
-                                if (t == null) {
-                                    listener.onResponse(r, filterInvoker, 
invocation);
-                                } else {
-                                    listener.onError(t, filterInvoker, 
invocation);
-                                }
-                            } catch (Throwable filterError) {
-                                t = filterError;
+                            if (t == null) {
+                                listener.onResponse(r, filterInvoker, 
invocation);
+                            } else {
+                                listener.onError(t, filterInvoker, invocation);
                             }
                         }
                     } else {
-                        try {
-                            filter.onResponse(r, filterInvoker, invocation);
-                        } catch (Throwable filterError) {
-                            t = filterError;
-                        }
+                        filter.onResponse(r, filterInvoker, invocation);
                     }
                 }
             });
-
             return asyncResult;
         }
 

Reply via email to