Proposal: Retry strategies
Author: speedflCreated Apr 23, 2025Updated Dec 31, 2025
Labelsinteraction
Introduction
This proposal is an umbrella proposal for #1006 and #1007
To add more flexibility we could support different retry strategies:
client := resty.New().
OnBeforeRequest(func(c *resty.Client, req *resty.Request) error {
// Set your current token
req.SetAuthToken(getCurrentToken())
return nil
}).
WithRetryStrategy(resty.RertyOn(401).WithHook(func(r *resty.Response, err error) error {
if r.StatusCode() == 401 {
// Refresh token here
retrun refreshToken()
})).
WithRetryStrategy(resty.RertyOn(428).WithCount(3)).
WithRetryStrategy(resty.Retry(func(r *resty.Response, err error) error {
// custom logic
return nil
})).Compared to #1006 and #1007 this issue could need more discussion so don't hesitate to challenge it
Source: go-resty/resty