feign icon indicating copy to clipboard operation
feign copied to clipboard

Custom ErrorDecoder and RetryableExceptions

Open Kidlike opened this issue 8 years ago • 11 comments

I have set up a custom ErrorDecoder which is used for all 4xx responses, but for example if the inbound server is down, my custom ErrorDecoder is never used, and instead just a RetryableException is thrown.

Is there something else I could override that will control what exception is thrown regardless of the scenario ?

Also something like this would help to create better logs... Now the logs are inconsistent because of this conditionality.

Kidlike avatar May 16 '18 12:05 Kidlike

I suspect that the Client instance you have configured is set up to automatically retry connection based exceptions. Do you have an example of the Builder configuration you used?

kdavisk6 avatar May 16 '18 14:05 kdavisk6

Sorry forgot to mention I use org.springframework.cloud.netflix.feign.FeignClient:

@FeignClient(name = "filerepo", url = "${filerepo.host}")

Kidlike avatar May 16 '18 14:05 Kidlike

That is a special Spring version of an auto-configured Feign client. Have you asked your question with the Spring Cloud folks? There are too many variables there for me to help you out. For example, you can manually configure a Client, or used the default one that Spring gives you, which is based on a number of different scenarios.

I suggest that you check with them first and see if there is something you can audit or update in your Spring configuration first.

kdavisk6 avatar May 16 '18 15:05 kdavisk6

Thanks, I will investigate from the Spring side of things :)

Kidlike avatar May 16 '18 15:05 Kidlike

@kdavisk6 It's the issue with default SynchronousMethodHandler, not with Spring Cloud. SynchronousMethodHandler invokes ErrorDecoder in case of http response only. If there's no http response (IOException thrown by Client) then it wrappes exception with RetryableException and throws it. code

Squiry avatar Jun 01 '18 08:06 Squiry

@Squiry Nice catch :)

Any suggestions?

Kidlike avatar Jun 01 '18 08:06 Kidlike

Well ErrorDecoder should decode erros and there's nothing to decode anyway. You can proxy Client and handle IOException there if you really need it. Or you can just handle RetryableException.

Squiry avatar Jun 01 '18 08:06 Squiry

Yeah at the moment I'm just handling RetryableException. I guess I'll stay like this. Thanks though !

Kidlike avatar Jun 01 '18 09:06 Kidlike

The current implementation treats all IOExceptions from the Client as something related to the communication and should be retried. This will continue for the maxAttempts and then throw the RetryableException out, if you use the default Retryer. If this is not the behavior you want, you can implement your own Retryer and process them accordingly.

kdavisk6 avatar Jul 04 '18 23:07 kdavisk6

Closing based on the last comment.

kdavisk6 avatar Dec 27 '19 22:12 kdavisk6

thanks

shavkat1121 avatar Apr 21 '22 04:04 shavkat1121