@@ -124,16 +124,13 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
124
124
}
125
125
}()
126
126
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
131
128
requestData , err := c .APIHandler .MarshalRequest (body , method , endpoint , log )
132
129
if err != nil {
133
130
return nil , err
134
131
}
135
132
136
- // Construct URL using the ConstructAPIResourceEndpoint function
133
+ // Construct URL with correct structure defined in api handler
137
134
url := c .APIHandler .ConstructAPIResourceEndpoint (c .InstanceName , endpoint , log )
138
135
139
136
// Initialize total request counter
@@ -160,10 +157,16 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
160
157
for time .Now ().Before (totalRetryDeadline ) { // Check if the current time is before the total retry deadline
161
158
req = req .WithContext (ctx )
162
159
resp , err = c .executeHTTPRequest (req , log , method , endpoint )
160
+ // Check for successful status code
163
161
if err == nil && resp .StatusCode >= 200 && resp .StatusCode < 300 {
164
162
return resp , c .handleSuccessResponse (resp , out , log , method , endpoint )
165
163
}
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
167
170
if errors .IsRateLimitError (resp ) || errors .IsTransientError (resp ) {
168
171
retryCount ++
169
172
if retryCount > c .clientConfig .ClientOptions .MaxRetryAttempts {
@@ -175,15 +178,15 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
175
178
time .Sleep (waitDuration )
176
179
continue
177
180
}
178
-
181
+ // Handle error responses
179
182
if err != nil || ! errors .IsRetryableStatusCode (resp .StatusCode ) {
180
183
if apiErr := errors .HandleAPIError (resp , log ); apiErr != nil {
181
184
err = apiErr
182
185
}
183
186
break
184
187
}
185
188
}
186
-
189
+ // Handles final non-API error.
187
190
if err != nil {
188
191
return nil , err
189
192
}
0 commit comments