Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented doRequest helper method #557

Merged
Prev Previous commit
Next Next commit
Added more detailed response for HTTP errors
  • Loading branch information
ezilber-akamai committed Jul 24, 2024
commit eebf30f4238f5e98e7ba4567f8a9eca3d4bdbdec
11 changes: 10 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,16 @@ func (c *HTTPClient) doRequest(ctx context.Context, method, url string, params R

// Check for HTTP errors
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("received non-2xx status code: %d", resp.StatusCode)
var errorDetails string
if resp.Body != nil {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
errorDetails = fmt.Sprintf("failed to read response body: %v", err)
} else {
errorDetails = string(bodyBytes)
}
}
return fmt.Errorf("received non-2xx status code: %d, details: %s", resp.StatusCode, errorDetails)
ezilber-akamai marked this conversation as resolved.
Show resolved Hide resolved
}

// Decode the response body
Expand Down