From 3bf883327e8aaa651149ffc7eec1f78d4e8a8292 Mon Sep 17 00:00:00 2001 From: kelgon Date: Fri, 28 Jul 2017 16:11:23 +0800 Subject: [PATCH] (fix #543)added body to error when Post encounter 4xx response --- weed/util/http_util.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/weed/util/http_util.go b/weed/util/http_util.go index 086584af7..ca9f7c50e 100644 --- a/weed/util/http_util.go +++ b/weed/util/http_util.go @@ -48,10 +48,14 @@ func Post(url string, values url.Values) ([]byte, error) { return nil, err } defer r.Body.Close() + b, err := ioutil.ReadAll(r.Body) if r.StatusCode >= 400 { - return nil, fmt.Errorf("%s: %s", url, r.Status) + if err != nil { + return nil, fmt.Errorf("%s: %d - %s", url, r.StatusCode, string(b)) + } else { + return nil, fmt.Errorf("%s: %s", url, r.Status) + } } - b, err := ioutil.ReadAll(r.Body) if err != nil { return nil, err }