Skip to content

Proposal: Retry count using function #1006

@speedfl

Description

@speedfl

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions