gojek / heimdall

An enhanced HTTP client for Go
http://gojek.tech
Apache License 2.0
2.63k stars 214 forks source link

Retry Based on Response Code #87

Open tooolbox opened 4 years ago

tooolbox commented 4 years ago

Currently looks like the retry mechanism will only engage if there's an actual error in sending the request, or if it's a 5xx response code.

It would be handy to be able to configure it so that it will retry on a non-2xx response code. I can do a PR if the maintainers are interested.

GarryGaller commented 4 years ago

A good idea. I just wanted to ask the package developer to do this. Add a statusForRetry field of type [] int to the Client structure, and replace the if response.StatusCode >= http.StatusInternalServerError condition by checking whether http code is included in statusForRetry. Better still, make a map where the key is the http status, and the value is a structure with the timeout, retryCount, and callback function fields.

arieltorti commented 2 years ago

Bumping, any updates on this ?

There's an implementation similar to what @GarryGaller proposed here: https://github.com/gojek/heimdall/pull/105