Skip to content

Proposal: Retry count using function #1006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
speedfl opened this issue Apr 23, 2025 · 0 comments
Open

Proposal: Retry count using function #1006

speedfl opened this issue Apr 23, 2025 · 0 comments

Comments

@speedfl
Copy link

speedfl commented 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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant