Skip to content

Conversation

codetruelle
Copy link

When an API call is returning a bad status code (!=200) and no body, the client return the body read error EOF instead of the error code. It's more difficult to debug and understand what happened.
A call to POST /cloud/project/*/instance with a bad or empty image id will return EOF.
With this patch, it return the 404 error saying an object is not found.
It's not perfect as the API should return the exact error, but more useful than EOF.

@deathiop
Copy link
Contributor

deathiop commented Apr 14, 2023

Hi there,

Thanks for contributing!
As per our contributing policy, may I please ask you to sign-off you commit? (git commit --amend -s --no-edit && git push -f).

Also, please squash these 4 commits.

@@ -397,24 +397,36 @@ func (c *Client) CallAPIWithContext(ctx context.Context, method, path string, re
// UnmarshalResponse checks the response and unmarshals it into the response
// type if needed Helper function, called from CallAPI
func (c *Client) UnmarshalResponse(response *http.Response, resType interface{}) error {
// Read all the response body
defer response.Body.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should stay here.

@@ -397,24 +397,36 @@ func (c *Client) CallAPIWithContext(ctx context.Context, method, path string, re
// UnmarshalResponse checks the response and unmarshals it into the response
// type if needed Helper function, called from CallAPI
func (c *Client) UnmarshalResponse(response *http.Response, resType interface{}) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (c *Client) UnmarshalResponse(response *http.Response, resType interface{}) error {
func (c *Client) UnmarshalResponse(response *http.Response, resType interface{}) error {
// Read all the response body
defer response.Body.Close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants