-
Notifications
You must be signed in to change notification settings - Fork 35
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
Fix API Error when error body is empty #68
base: master
Are you sure you want to change the base?
Conversation
Hi there, Thanks for contributing! 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() |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
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.