ref(client): use anonymous embedded error

/cc @technosophos
pull/419/head
Adam Reese 9 years ago
parent 6adaa45cce
commit ea7166b83a

@ -118,7 +118,7 @@ func (c *Client) Delete(endpoint string, v interface{}) (*Response, error) {
func (c *Client) NewRequest(method, endpoint string, payload interface{}) *Request { func (c *Client) NewRequest(method, endpoint string, payload interface{}) *Request {
u, err := c.url(endpoint) u, err := c.url(endpoint)
if err != nil { if err != nil {
return &Request{err: err} return &Request{error: err}
} }
body := prepareBody(payload) body := prepareBody(payload)
@ -153,7 +153,7 @@ func (c *Client) Exec(req *Request, v interface{}) (*Response, error) {
// Result checks status code and decodes a response body // Result checks status code and decodes a response body
func (c *Client) Result(resp *Response, v interface{}) (*Response, error) { func (c *Client) Result(resp *Response, v interface{}) (*Response, error) {
switch { switch {
case resp.err != nil: case resp.error != nil:
return resp, resp return resp, resp
case resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices: case resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices:
return resp, resp.HTTPError() return resp, resp.HTTPError()
@ -164,8 +164,8 @@ func (c *Client) Result(resp *Response, v interface{}) (*Response, error) {
// Do send a request and returns a response // Do send a request and returns a response
func (c *Client) Do(req *Request) *Response { func (c *Client) Do(req *Request) *Response {
if req.err != nil { if req.error != nil {
return &Response{err: req} return &Response{error: req}
} }
client := &http.Client{ client := &http.Client{
@ -254,23 +254,13 @@ func DefaultServerURL(host string) (*url.URL, error) {
// Request wraps http.Request to include error // Request wraps http.Request to include error
type Request struct { type Request struct {
*http.Request *http.Request
err error error
}
// Error implements the error interface.
func (r *Request) Error() string {
return fmt.Sprint("%s", r.err)
} }
// Response wraps http.Response to include error // Response wraps http.Response to include error
type Response struct { type Response struct {
*http.Response *http.Response
err error error
}
// Error implements the error interface.
func (r *Response) Error() string {
return fmt.Sprint("%s", r.err)
} }
// HTTPError creates a new HTTPError from response // HTTPError creates a new HTTPError from response

Loading…
Cancel
Save