Skip to content

Commit 63d134c

Browse files
committed
Handle error and success responses in executeRequest function
1 parent f06fb88 commit 63d134c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

httpclient/httpclient_request.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,14 @@ func (c *Client) executeRequest(method, endpoint string, body, out interface{},
279279
// Checks for the presence of a deprecation header in the HTTP response and logs if found.
280280
CheckDeprecationHeader(resp, log)
281281

282-
// Handle the response
283-
if err := c.APIHandler.UnmarshalResponse(resp, out, log); err != nil {
284-
return resp, err
282+
// Check for successful status code
283+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
284+
// Handle error responses
285+
return nil, c.handleErrorResponse(resp, log, "Failed to process the HTTP request", method, endpoint)
286+
} else {
287+
// Handle successful responses
288+
return resp, c.handleSuccessResponse(resp, out, log, method, endpoint)
285289
}
286-
287-
return resp, nil
288290
}
289291

290292
// executeHTTPRequest sends an HTTP request using the client's HTTP client. It logs the request and error details, if any,

0 commit comments

Comments
 (0)