ErrorDecoder not catching SocketTimeoutException

Viewed 132

With feign builder I am making call to external URL. I have set readTimeout as 2seconds, I am getting the SocketTimeoutException but it's not going to ErrorDecoder.

Feign Builder Configuration:

Options options = new Options(10000, TimeUnit.MILLISECONDS, 2000,
        TimeUnit.MILLISECONDS, false);

return Feign.builder()
        .logLevel(level)
        .client(client)
        .retryer(Retryer.NEVER_RETRY)
        .options(options)
        .errorDecoder(feignErrorDecoder())
        .exceptionPropagationPolicy(UNWRAP);

private ErrorDecoder feignErrorDecoder() {
    return (methodKey, response) -> {
      return new MyCustomException("ERROR_TIMEOUT",
          "Timeout Occurred: " + response.status());
    };
  }

When I call service exception is not going to ErrorDecoder. java.lang.reflect.UndeclaredThrowableException coming.

1 Answers

ErrorDecoder is not called when an IOException (SocketTimeoutException) is thrown. See SynchronousMethodHandler#executeAndDecode(...). In general decoders are only called when a response is returend by the api-call. The ErrorCoder is only called when the http error code is not 2xx and 4xx.

Related