Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
log response body after checking errors. allow for consuming twice
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed May 17, 2017
1 parent 8c9bdbb commit e236963
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package moneybird
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
Expand Down Expand Up @@ -66,13 +67,17 @@ func (c *Client) execute(method string, path string, env *envelope) (*Response,
c.Logger.Printf("Moneybird: %s %s\n", req.Method, req.URL)
}
res, err := c.HTTPClient.Do(req)
if c.Logger != nil {
c.Logger.Printf("Moneybird: %s", res.Status)
}

if err != nil {
return nil, err
}

if c.Logger != nil {
body, _ := ioutil.ReadAll(res.Body)
c.Logger.Printf("Moneybird: %s", res.Status)
c.Logger.Printf("Moneybird: %s", body)
res.Body = ioutil.NopCloser(bytes.NewBuffer(body))
}

return &Response{res}, nil
}

0 comments on commit e236963

Please sign in to comment.