Skip to content

Commit

Permalink
actually return error
Browse files Browse the repository at this point in the history
only try to read response if there was no error
  • Loading branch information
mschoch authored and mattbaird committed Oct 31, 2012
1 parent ce231a5 commit ba9c3b7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions api/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ func (r *Request) SetBody(body io.Reader) {

func (r *Request) Do(v interface{}) (string, error) {
res, err := http.DefaultClient.Do((*http.Request)(r))
defer res.Body.Close()
bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
return "", nil
return "", err
}

defer res.Body.Close()
bodyBytes, err := ioutil.ReadAll(res.Body)

if v != nil {
jsonErr := json.Unmarshal(bodyBytes, v)
if jsonErr != nil {
Expand Down

0 comments on commit ba9c3b7

Please sign in to comment.