Advertisement

Spring Cloud Feign实现定制化异常捕捉

阅读量:

feign client 2.x版本中默认存在的异常情况

复制代码
    public static FeignException errorStatus(String methodKey, Response response) {
    String message = format("status %s reading %s", response.status(), methodKey);
    try {
      Object body = toString.decode(methodKey, response, String.class);
      if (body != null) {
        response = Response.create(response.status(), response.reason(), response.headers(), body.toString());
        message += "; content:\n" + body;
      }
    } catch (IOException ignored) { // NOPMD
    }
    return new FeignException(message);
      }
    
    
    
    AI写代码java

全部评论 (0)

还没有任何评论哟~