go-resty / resty

Simple HTTP and REST client library for Go
MIT License
9.95k stars 704 forks source link

Overwrite Retryconditions #868

Open wasserholz opened 20 hours ago

wasserholz commented 20 hours ago

First of all, thanks for this great rest client.

Currently it is not possible to overwrite retry conditions on a request

Use case: Most requests to a specific API should retry on any error except for one endpoint. For that one endpoint I am creating an object and the endpoint returns 400 with an app error code specific to that endpoint. As the object exists, it is fine to not retry.

I have now a client wide retry on error, AddRetryAfterErrorCondition(), but for that one request I want it do use my customer retry function only. This would only work if I manually remove the client wide retry condition or use a new client for this specific request.

It would be great to be able to overwrite client wide configuration in each request, so it is possible to avoid work-arounds.

wasserholz commented 20 hours ago

For now I have encapsulated the rest client into a wrapper type with receiver functions, which then add the retry conditions on each request to avoid repetition and client wide config.

jeevatkm commented 10 hours ago

@wasserholz Thanks for reaching out. In the upcoming Resty v3, retry controls will be added to the Request level to prevent retrying on particular requests; refer to #752. Can you elaborate on the overwrite condition? I do not understand. Typically, conditions will not occur when you turn off the retry on request.