Skip to content

Commit a388d94

Browse files
committed
Add status message to log for non-retryable errors
1 parent 6c539b8 commit a388d94

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

httpclient/httpclient_request.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,16 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
161161
if err == nil && resp.StatusCode >= 200 && resp.StatusCode < 300 {
162162
return resp, c.handleSuccessResponse(resp, out, log, method, endpoint)
163163
}
164+
165+
// Leverage TranslateStatusCode for more descriptive error logging
166+
statusMessage := errors.TranslateStatusCode(resp.StatusCode)
167+
164168
// Check for non-retryable errors
165169
if resp != nil && errors.IsNonRetryableStatusCode(resp) {
166-
log.Info("Non-retryable error received", zap.Int("status_code", resp.StatusCode))
170+
log.Info("Non-retryable error received", zap.Int("status_code", resp.StatusCode), zap.String("status_message", statusMessage))
167171
return resp, errors.HandleAPIError(resp, log)
168172
}
173+
169174
// Check for retryable errors
170175
if errors.IsRateLimitError(resp) || errors.IsTransientError(resp) {
171176
retryCount++
@@ -174,15 +179,17 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
174179
break
175180
}
176181
waitDuration := calculateBackoff(retryCount)
177-
log.Warn("Retrying request due to error", zap.String("method", method), zap.String("endpoint", endpoint), zap.Int("retryCount", retryCount), zap.Duration("waitDuration", waitDuration), zap.Error(err))
182+
log.Warn("Retrying request due to error", zap.String("method", method), zap.String("endpoint", endpoint), zap.Int("retryCount", retryCount), zap.Duration("waitDuration", waitDuration), zap.Error(err), zap.String("status_message", statusMessage))
178183
time.Sleep(waitDuration)
179184
continue
180185
}
186+
181187
// Handle error responses
182188
if err != nil || !errors.IsRetryableStatusCode(resp.StatusCode) {
183189
if apiErr := errors.HandleAPIError(resp, log); apiErr != nil {
184190
err = apiErr
185191
}
192+
log.Error("API error", zap.String("status_message", statusMessage), zap.Error(err))
186193
break
187194
}
188195
}

0 commit comments

Comments
 (0)