wxbty commented on code in PR #11088:
URL: https://github.com/apache/dubbo/pull/11088#discussion_r1109932295


##########
dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeHandler.java:
##########
@@ -82,15 +87,31 @@ void handleRequest(final ExchangeChannel channel, Request 
req) throws RemotingEx
         Response res = new Response(req.getId(), req.getVersion());
         if (req.isBroken()) {
             Object data = req.getData();
+            Throwable error = req.getError();
 
             String msg;
             if (data == null) {
                 msg = null;
-            } else if (data instanceof Throwable) {
-                msg = StringUtils.toString((Throwable) data);
             } else {
                 msg = data.toString();
             }
+
+            if (error != null) {
+                msg = StringUtils.toString(error);
+                // Give ExceptionProcessors a chance to retry request handle 
or custom exception information.
+                String exPs = System.getProperty(EXCEPTION_PROCESSOR_KEY);
+                if (StringUtils.isNotBlank(exPs)) {
+                    ExtensionLoader<ExceptionProcessor> extensionLoader = 
ApplicationModel.defaultModel().getDefaultModule().getExtensionLoader(ExceptionProcessor.class);
+                    ExceptionProcessor expProcessor = 
extensionLoader.getOrDefaultExtension(exPs);
+                    boolean handleError = 
expProcessor.shouldHandleError(error);
+                    if (handleError) {
+                        // Allow to custom error message, return directly
+                        // Or interrupt, reHandle the process, process req, 
and continue to return normal information
+                        msg = 
Optional.ofNullable(expProcessor.wrapAndHandleException(channel, 
req)).orElse(msg);

Review Comment:
   RetryHandleException will be thrown up and caught here in DecodeHandler, 
which is specially designed
   
   ```java
   public void received(Channel channel, Object message) throws 
RemotingException {
       doRecveived(message);
       try {
           handler.received(channel, message);
       } catch (RetryHandleException e) {
           if (message instanceof Request) {
               Request request = (Request) message;
               retry(request.getData());
           } else {
               // Retry only once, and only Request will throw an 
RetryHandleException
               throw new RemotingException(channel, "Unknown error encountered 
when retry handle: " + e.getMessage());
           }
           handler.received(channel, message);
       }
   }
   ```
   
   
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to