Fix crash in http logging - fixes #223

A nil-pointer exception was caused if the http transaction ever
resulted in a go error while using `--dump-bodies`.  Now don't ignore
the error and log it instead of the http body.
This commit is contained in:
Nick Craig-Wood 2015-11-26 16:52:54 +00:00
parent 36f1bc4a8a
commit 8057d668bb

View file

@ -48,10 +48,14 @@ func (t *LoggedTransport) RoundTrip(req *http.Request) (resp *http.Response, err
log.Println(string(buf))
log.Println(separatorReq)
resp, err = t.wrapped.RoundTrip(req)
buf, _ = httputil.DumpResponse(resp, t.logBody)
log.Println(separatorResp)
log.Println("HTTP RESPONSE")
log.Println(string(buf))
if err != nil {
log.Printf("Error: %v\n", err)
} else {
buf, _ = httputil.DumpResponse(resp, t.logBody)
log.Println(string(buf))
}
log.Println(separatorResp)
return resp, err
}