#1006·resty

Proposal: Retry count using function

Author: speedflCreated Apr 23, 2025Updated Apr 23, 2025

Hello.

I would like to add a custom retry count based on the status. Example:

  • On 428 I could retry x time
  • On 401 I would like to refresh my token and retry only one time

Proposal:

go

client := resty.New().
    OnBeforeRequest(func(c *resty.Client, req *resty.Request) error {
        // Set your current token
        req.SetAuthToken(getCurrentToken())
        return nil
    }).
    SetRetryCountFunc(func(r *resty.Response, err error) int {
        if r.StatusCode() == 401 {
            return 1
        } 
        if r.StatusCode() == 428 {
            return 3
        } 
        return 0
    })

I could contribute if you want.