Netflix Feign 中的异常处理
Exception Handling in Netflix Feign
我正在使用 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?
我想您正在使用 Netflix Feign
独立而不是 spring 启动。
您可以在构建 Feign 客户端时轻松集成自定义 ErrorDecoder。
Feign.builder().errorDecoder(new MyCustomErrorDecoder())
.target(MyApi.class, "https://api.hostname.com");
更多细节请查看官方文档here
我正在使用 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?
我想您正在使用 Netflix Feign
独立而不是 spring 启动。
您可以在构建 Feign 客户端时轻松集成自定义 ErrorDecoder。
Feign.builder().errorDecoder(new MyCustomErrorDecoder())
.target(MyApi.class, "https://api.hostname.com");
更多细节请查看官方文档here