Skip to content

Retry with new authorization token #548

Closed Answered by kecci
paulius-miksys asked this question in Q&A
Discussion options

You must be logged in to vote

I want to refresh my authorization token when it expires and I get 401. So I use AddRetryCondition (check if response is 401), AddRetryHook to update header and SetRetryCount(1).

I set a new header with SetHeader in the func I pass to AddRetryHook. Interesting thing that resty still does a retry with an old authorization token even the header was successfully updated. As a result I get 401 again.

I'm trying to define your code like this:

package main

import (
	"net/http"
	"time"

	"github.com/go-resty/resty/v2"
)

func main() {

	// Create a Resty Client
	client := resty.New()

	// Retries are configured per client
	client = client.
		// Set retry count to non zero to enable retries
		S…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by jeevatkm
Comment options

You must be logged in to vote
1 reply
@danhawkins
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants