Add HTTP error message from peer to error returned from httpGetter.Get

This commit is contained in:
Marnix Bouhuis 2022-07-14 11:47:40 +02:00
parent 4707649ec3
commit 131b5ec788
No known key found for this signature in database
GPG Key ID: 0977311D7DD43BFD

View File

@ -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()