Commit bc49fe62 authored by Adam Reese's avatar Adam Reese

ref(client): add a success helper function

parent ea7166b8
......@@ -155,7 +155,7 @@ func (c *Client) Result(resp *Response, v interface{}) (*Response, error) {
switch {
case resp.error != nil:
return resp, resp
case resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices:
case !resp.Success():
return resp, resp.HTTPError()
}
......@@ -263,6 +263,11 @@ type Response struct {
error
}
// Success returns true if the status code is 2xx
func (r *Response) Success() bool {
return r.StatusCode >= 200 && r.StatusCode < 300
}
// HTTPError creates a new HTTPError from response
func (r *Response) HTTPError() error {
defer r.Body.Close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment