Search code examples
springtimeoutfeign

How to handle feign client connection timeout


I have below code to check this error but I am not getting timeout error its going to else condition

Response response = null;
        try {
            response = client.getResponse(URI.create(uri), headers, reuest);
        } catch (Exception ex) {

            if(ex instanceof SocketTimeoutException){
                throw new ExternalClientException(Errors.TIMEOUT_ERROR);
            } else {
                throw new ExternalClientException(Errors.UNEXPECTED_ERROR);
            }
        }


Solution

  • You need to catch feign.RetryableException instead of SocketTimeoutException.

    javadoc