Skip to content

Commit bba15c2

Browse files
authored
Merge pull request #52 from deploymenttheory/dev
Dev
2 parents acd1c53 + c4969de commit bba15c2

File tree

2 files changed

+11
-55
lines changed

2 files changed

+11
-55
lines changed

httpclient/httpclient_headers_old.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

httpclient/httpclient_request.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,13 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
124124
}
125125
}()
126126

127-
// Determine which set of encoding and content-type request rules to use
128-
// apiHandler := c.APIHandler
129-
130-
// Marshal Request with correct encoding
127+
// Marshal Request with correct encoding defined in api handler
131128
requestData, err := c.APIHandler.MarshalRequest(body, method, endpoint, log)
132129
if err != nil {
133130
return nil, err
134131
}
135132

136-
// Construct URL using the ConstructAPIResourceEndpoint function
133+
// Construct URL with correct structure defined in api handler
137134
url := c.APIHandler.ConstructAPIResourceEndpoint(c.InstanceName, endpoint, log)
138135

139136
// Initialize total request counter
@@ -160,10 +157,16 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
160157
for time.Now().Before(totalRetryDeadline) { // Check if the current time is before the total retry deadline
161158
req = req.WithContext(ctx)
162159
resp, err = c.executeHTTPRequest(req, log, method, endpoint)
160+
// Check for successful status code
163161
if err == nil && resp.StatusCode >= 200 && resp.StatusCode < 300 {
164162
return resp, c.handleSuccessResponse(resp, out, log, method, endpoint)
165163
}
166-
164+
// Check for non-retryable errors
165+
if resp != nil && errors.IsNonRetryableError(resp) {
166+
log.Info("Non-retryable error received", zap.Int("status_code", resp.StatusCode))
167+
return resp, errors.HandleAPIError(resp, log)
168+
}
169+
// Check for retryable errors
167170
if errors.IsRateLimitError(resp) || errors.IsTransientError(resp) {
168171
retryCount++
169172
if retryCount > c.clientConfig.ClientOptions.MaxRetryAttempts {
@@ -175,15 +178,15 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
175178
time.Sleep(waitDuration)
176179
continue
177180
}
178-
181+
// Handle error responses
179182
if err != nil || !errors.IsRetryableStatusCode(resp.StatusCode) {
180183
if apiErr := errors.HandleAPIError(resp, log); apiErr != nil {
181184
err = apiErr
182185
}
183186
break
184187
}
185188
}
186-
189+
// Handles final non-API error.
187190
if err != nil {
188191
return nil, err
189192
}

0 commit comments

Comments
 (0)