ref(client): add a success helper function

pull/419/head
Adam Reese 9 years ago
parent ea7166b83a
commit bc49fe625e

@ -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()

Loading…
Cancel
Save