You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "iqinning (via GitHub)" <gi...@apache.org> on 2023/05/07 22:31:15 UTC

[GitHub] [dubbo] iqinning commented on pull request #12246: fix When the exception handling class cannot be obtained, it should recursively search the base class(#12245)

iqinning commented on PR #12246:
URL: https://github.com/apache/dubbo/pull/12246#issuecomment-1537554651

   > ExceptionHandler的功能是来自于spring的controllerAdvice和restEasy的ExceptionMapper,这两者都是对某一个具体类型的Exception做处理的,我看这个更改逻辑是为了向上查找super的ExceptionHandler,就不是某种具体类型的处理了,
   
   据我了解,不管是 spring mvc 的异常处理器查找机制,还是rest easy 都是往基类查找的以下是 rest-easy 处理代码
   
   ```
   
   /**
       * Execute an ExceptionMapper if one exists for the given exception.  Recurse to base class if not found
       *
       * @param exception
       * @return true if an ExceptionMapper was found and executed
       */
      @SuppressWarnings(value = "unchecked")
      public Response executeExceptionMapper(Throwable exception)
      {
         ExceptionMapper mapper = null;
   
         Class causeClass = exception.getClass();
         while (mapper == null) {
            if (causeClass == null) break;
            mapper = providerFactory.getExceptionMappers().get(causeClass);
            if (mapper == null) causeClass = causeClass.getSuperclass();
         }
         if (mapper != null) {
            mapperExecuted = true;
            Response jaxrsResponse = mapper.toResponse(exception);
            if (jaxrsResponse == null) {
               jaxrsResponse = Response.status(204).build();
            }
            return jaxrsResponse;
         }
         return null;
      }
   
   ```
   
   
   
   


-- 
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