我正在应用程序中使用Feign进行HTTP调用。我也提供了一个ErrorDecoder类,但是当请求超时时,流程没有到达我的ErrorDecoder类。我在这里想念什么?我想做的是从errordecoder类中抛出一个自定义错误,然后在GlobalExceptionHandler中捕获它并返回408状态代码
@FeignClient(name="finacle-service" ,url = "${feign.client.url.finacleUrl}", configuration = FinacleProxyConfig.class)
public interface FinacleProxy {
@PostMapping
String getCif(@RequestBody String request);
@PostMapping
String updateFinaclePns(@RequestBody String request);
}
public class FinacleProxyConfig {
@Bean
public static Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
@Bean
public static Request.Options requestOptions() {
return new Request.Options(3000, 3000);
}
@Bean
public static FinacleErrorDecoder errorDecoder(){
return new FinacleErrorDecoder();
}
}
spring.application.name = bds-intgeration-services
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
spring.cloud.services.registrationMethod=direct
logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG
feign.httpclient.disableSslValidation=true
feign.httpclient.enabled=false
feign.okhttp.enabled=true
feign.hystrix.enabled = false
public class FinacleErrorDecoder implements ErrorDecoder {
private final ErrorDecoder defaultErrorDecoder = new Default();
@Override
public Exception decode(String methodkey, Response response) {
if(response.status() == 408){
return FinacleTimedOutException.builder().message("Request timed out to finacle").build();
}
return defaultErrorDecoder.decode(methodkey, response);
}
}