Skip to content

Commit

Permalink
Merge pull request #439 from hashicorp/sebasslash/retry-ping-request
Browse files Browse the repository at this point in the history
Extend config interface to support setting `retryServerErrors`
  • Loading branch information
sebasslash committed Jun 24, 2022
2 parents f759c44 + 8bf7b8e commit cc5d816
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
# v1.4.0 (Unreleased)

## Enhancements
* Adds `RetryServerErrors` field to the `Config` object by @sebasslash [#439](https://github.com/hashicorp/go-tfe/pull/439)

# v1.3.0

## Enhancements
Expand Down
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.
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

0 comments on commit cc5d816

Please sign in to comment.