Skip to content

Proposal: Retry strategies #1008

@speedfl

Description

@speedfl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions