Skip to content

Commit af61bee

Browse files
committed
add Request URI and response body to debugging output
1 parent b8d3db5 commit af61bee

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

api/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package api
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"io"
78
"net/http"
89
"strings"
910

1011
"github.com/exercism/cli/config"
12+
"github.com/exercism/cli/debug"
1113
)
1214

1315
const (
@@ -45,6 +47,7 @@ func (c *Client) NewRequest(method, url string, body io.Reader) (*http.Request,
4547
if err != nil {
4648
return nil, err
4749
}
50+
debug.Println("NewRequest:", method, url)
4851

4952
req.Header.Set("User-Agent", UserAgent)
5053
req.Header.Set("Content-Type", "application/json")
@@ -71,7 +74,12 @@ func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error) {
7174
default:
7275
if v != nil {
7376
defer res.Body.Close()
74-
if err := json.NewDecoder(res.Body).Decode(v); err != nil {
77+
78+
var bodyCopy bytes.Buffer
79+
body := io.TeeReader(res.Body, &bodyCopy)
80+
81+
if err := json.NewDecoder(body).Decode(v); err != nil {
82+
debug.Println("res.Body:", bodyCopy.String())
7583
return nil, fmt.Errorf("error parsing API response - %s", err)
7684
}
7785
}

0 commit comments

Comments
 (0)