Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions httpclient/httpclient_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ func (c *Client) executeRequest(method, endpoint string, body, out interface{},
// Check for successful status code
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
// Handle error responses
return nil, c.handleErrorResponse(resp, log, "Failed to process the HTTP request", method, endpoint)
//return nil, c.handleErrorResponse(resp, log, "Failed to process the HTTP request", method, endpoint)
return nil, c.handleErrorResponse(resp, out, log, method, endpoint)
} else {
// Handle successful responses
return resp, c.handleSuccessResponse(resp, out, log, method, endpoint)
Expand Down Expand Up @@ -349,7 +350,7 @@ func (c *Client) executeHTTPRequest(req *http.Request, log logger.Logger, method
//
// Returns:
// - An error object parsed from the HTTP response, indicating the nature of the failure.
func (c *Client) handleErrorResponse(resp *http.Response, log logger.Logger, errorMessage, method, endpoint string) error {
func (c *Client) handleErrorResponseV1(resp *http.Response, log logger.Logger, errorMessage, method, endpoint string) error {
apiErr := errors.HandleAPIError(resp, log)

// Log the provided error message along with method, endpoint, and status code.
Expand All @@ -363,6 +364,23 @@ func (c *Client) handleErrorResponse(resp *http.Response, log logger.Logger, err
return apiErr
}

func (c *Client) handleErrorResponse(resp *http.Response, out interface{}, log logger.Logger, method, endpoint string) error {
if err := c.APIHandler.HandleResponse(resp, out, log); err != nil {
log.Error("Failed to unmarshal HTTP response",
zap.String("method", method),
zap.String("endpoint", endpoint),
zap.Error(err),
)
Comment on lines +369 to +373

Check warning

Code scanning / gosec

Errors unhandled.

Errors unhandled.
return err
}
log.Info("HTTP request succeeded",
zap.String("method", method),
zap.String("endpoint", endpoint),
zap.Int("status_code", resp.StatusCode),
)
return nil
}

// handleSuccessResponse unmarshals a successful HTTP response into the provided output parameter and logs the
// success details. It's designed for use when the response indicates success (status code within 200-299).
// The function logs the request's success and, in case of unmarshalling errors, logs the failure and returns the error.
Expand Down Expand Up @@ -462,7 +480,8 @@ func (c *Client) DoMultipartRequest(method, endpoint string, fields map[string]s
// Check for successful status code
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
// Handle error responses
return nil, c.handleErrorResponse(resp, log, "Failed to process the HTTP request", method, endpoint)
//return nil, c.handleErrorResponse(resp, log, "Failed to process the HTTP request", method, endpoint)
return nil, c.handleErrorResponse(resp, out, log, method, endpoint)
} else {
// Handle successful responses
return resp, c.handleSuccessResponse(resp, out, log, method, endpoint)
Expand Down