Skip to content
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

Extend config interface to support setting retryServerErrors #439

Merged
merged 2 commits into from Jun 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 15 additions & 9 deletions tfe.go
Expand Up @@ -66,17 +66,21 @@ type Config struct {

// RetryLogHook is invoked each time a request is retried.
RetryLogHook RetryLogHook

// RetryServerErrors enables the retry logic in the client.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be specific about which errors are retried here and in the CHANGELOG. I think it's just 500 and 429?

RetryServerErrors bool
}

// DefaultConfig returns a default config structure.

func DefaultConfig() *Config {
config := &Config{
Address: os.Getenv("TFE_ADDRESS"),
BasePath: DefaultBasePath,
Token: os.Getenv("TFE_TOKEN"),
Headers: make(http.Header),
HTTPClient: cleanhttp.DefaultPooledClient(),
Address: os.Getenv("TFE_ADDRESS"),
BasePath: DefaultBasePath,
Token: os.Getenv("TFE_TOKEN"),
Headers: make(http.Header),
HTTPClient: cleanhttp.DefaultPooledClient(),
RetryServerErrors: false,
}

// Set the default address if none is given.
Expand Down Expand Up @@ -196,6 +200,7 @@ func NewClient(cfg *Config) (*Client, error) {
if cfg.RetryLogHook != nil {
config.RetryLogHook = cfg.RetryLogHook
}
config.RetryServerErrors = cfg.RetryServerErrors
}

// Parse the address to make sure its a valid URL.
Expand All @@ -216,10 +221,11 @@ func NewClient(cfg *Config) (*Client, error) {

// Create the client.
client := &Client{
baseURL: baseURL,
token: config.Token,
headers: config.Headers,
retryLogHook: config.RetryLogHook,
baseURL: baseURL,
token: config.Token,
headers: config.Headers,
retryLogHook: config.RetryLogHook,
retryServerErrors: config.RetryServerErrors,
}

client.http = &retryablehttp.Client{
Expand Down