From 131b5ec788f0a61583018091d2e5416f0a21251f Mon Sep 17 00:00:00 2001 From: Marnix Bouhuis Date: Thu, 14 Jul 2022 11:47:40 +0200 Subject: [PATCH] Add HTTP error message from peer to error returned from httpGetter.Get --- http.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/http.go b/http.go index b1dc10a..3b09f2f 100644 --- a/http.go +++ b/http.go @@ -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()