Skip to content

Commit

Permalink
fix error message for director.ClientRequest
Browse files Browse the repository at this point in the history
Signed-off-by: dmitriy kalinin <[email protected]>
  • Loading branch information
tjvman authored and cppforlife committed Aug 18, 2017
1 parent f63b80d commit c845370
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
14 changes: 6 additions & 8 deletions director/client_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ func (r ClientRequest) readResponse(resp *http.Response, out io.Writer) ([]byte,
if err == nil {
r.logger.Debug(logTag, "Dumping Director client response:\n%s", string(b))
}

respBody, err = ioutil.ReadAll(resp.Body)
if err != nil {
return nil, nil, bosherr.WrapError(err, "Reading Director response")
}
}

not200 := resp.StatusCode != http.StatusOK
Expand All @@ -230,14 +235,7 @@ func (r ClientRequest) readResponse(resp *http.Response, out io.Writer) ([]byte,
return nil, resp, bosherr.Errorf(msg, resp.StatusCode, respBody)
}

var err error

if out == nil {
respBody, err = ioutil.ReadAll(resp.Body)
if err != nil {
return nil, nil, bosherr.WrapError(err, "Reading Director response")
}
} else {
if out != nil {
showProgress := true

if typedOut, ok := out.(ShouldTrackDownload); ok {
Expand Down
13 changes: 13 additions & 0 deletions director/client_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ var _ = Describe("ClientRequest", func() {
Expect(resp).ToNot(BeNil())
})

It("includes response body in the error if response errors", func() {
server.SetHandler(0, ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/path"),
ghttp.RespondWith(0, "body"),
))

body, resp, err := req.RawGet("/path", nil, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("'body'"))
Expect(body).To(BeNil())
Expect(resp).ToNot(BeNil())
})

It("does not track downloading", func() {
fileReporter := &fakedir.FakeFileReporter{}
req = buildReq(fileReporter)
Expand Down

0 comments on commit c845370

Please sign in to comment.