Skip to content

Commit

Permalink
Merge pull request #46 from MarnixBouhuis/add-peer-error-message-to-e…
Browse files Browse the repository at this point in the history
…rror

Add HTTP error message from peer to error returned from httpGetter.Get
  • Loading branch information
thrawn01 authored Jul 28, 2022
2 parents 4707649 + 131b5ec commit abdfdfb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ func (h *httpGetter) Get(ctx context.Context, in *pb.GetRequest, out *pb.GetResp
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return fmt.Errorf("server returned: %v", res.Status)
msg, _ := ioutil.ReadAll(io.LimitReader(res.Body, 10*1024*1024)) // Limit reading the error body to max 10 MiB
return fmt.Errorf("server returned: %v, %v", res.Status, msg)
}
b := bufferPool.Get().(*bytes.Buffer)
b.Reset()
Expand Down

0 comments on commit abdfdfb

Please sign in to comment.