【问题标题】:What exceptions does feign.RetryableException wrap?feign.RetryableException 包装了哪些异常?
【发布时间】:2019-12-27 23:48:54
【问题描述】:

文档告诉我 HTTP 503 响应被认为是可重试的,一些例外情况也是如此。

根据经验,我知道 feign.RetryableException 包装了 java.net.ConnectException 和其他 j.n.SocketExceptions,但我看不出这是在哪里发生的。

其他类似 java.net.SocketTimeoutException 是否被 feign.RetryableException 包裹?

【问题讨论】:

    标签: java hystrix spring-cloud-feign feign


    【解决方案1】:

    您可以查看feign.SynchronousMethodHandler中的代码:

    try {
      response = client.execute(request, options);
    } catch (IOException e) {
      if (logLevel != Logger.Level.NONE) {
        logger.logIOException(metadata.configKey(), logLevel, e, elapsedTime(start));
      }
      throw errorExecuting(request, e);
    }
    
    
    static FeignException errorExecuting(Request request, IOException cause) {
      return new RetryableException(
          format("%s executing %s %s", cause.getMessage(), request.httpMethod(), request.url()),
          request.httpMethod(),
          cause,
          null);
    }
    

    所以如果异常扩展IOException,那么它将被包装。

    【讨论】:

      【解决方案2】:

      在 Feign 中,IOExceptions 是唯一被自动包装的异常。如果还有其他情况需要调用 Feign 的重试功能,请创建 ErrorDecoder 并返回 RetryableException。例如,请参阅Feign Documentation

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-09
        • 1970-01-01
        • 2023-03-02
        相关资源
        最近更新 更多