【问题标题】:Exception Handling in Netflix FeignNetflix Feign 中的异常处理
【发布时间】:2019-03-13 03:22:57
【问题描述】:

我正在使用 Netflix Feign 调用 HTTP 请求,如下所示 -

@Headers("Content-Type: application/json; Accept: application/json")
public interface EmployeeClient {

  @RequestLine("POST")
  @Headers("client-id: TEST")   
  EmployeeResponse employee(EmployeeRequest employeeRequest);
}

如果服务抛出错误或服务不可访问或关闭,我该如何处理此处的异常。如何使用 ErrorDecoder?

【问题讨论】:

    标签: java netflix-feign


    【解决方案1】:

    我想您正在使用 Netflix Feign 独立而不是 Spring Boot。

    您可以在构建 Feign 客户端时轻松集成自定义 ErrorDecoder。

    Feign.builder().errorDecoder(new MyCustomErrorDecoder())
                     .target(MyApi.class, "https://api.hostname.com");
    

    更多详情请查看官方文档here

    【讨论】:

      猜你喜欢
      • 2020-04-28
      • 2019-07-27
      • 2016-12-11
      • 2016-12-17
      • 2017-05-21
      • 2016-12-09
      • 2023-04-03
      • 2020-06-26
      • 2020-04-20
      相关资源
      最近更新 更多