配置的伪装,但在请求超时时,不使用给定的ErrorDecoder类

时间:2019-09-26 10:52:19

标签: java spring spring-boot spring-cloud feign

我正在应用程序中使用Feign进行HTTP调用。我也提供了一个ErrorDecoder类,但是当请求超时时,流程没有到达我的ErrorDecoder类。我在这里想念什么?我想做的是从errordecoder类中抛出一个自定义错误,然后在GlobalExceptionHandler中捕获它并返回408状态代码

FeignClient

@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);


}

FeignConfigclass

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();
  }

}

application.properties

 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);
  }
}

0 个答案:

没有答案