From 1bc290d4a73196cc6ff3ef9bc23bdeff91fbe98c Mon Sep 17 00:00:00 2001 From: ioito Date: Mon, 19 Aug 2019 21:34:58 +0800 Subject: [PATCH] fix: httputils show error when resp body is not dict --- pkg/util/httputils/httputils.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/util/httputils/httputils.go b/pkg/util/httputils/httputils.go index f7438c46d2..b973338f77 100644 --- a/pkg/util/httputils/httputils.go +++ b/pkg/util/httputils/httputils.go @@ -279,7 +279,7 @@ func ParseJSONResponse(resp *http.Response, err error, debug bool) (http.Header, } var jrbody jsonutils.JSONObject = nil - if len(rbody) > 0 { + if len(rbody) > 0 && string(rbody[0]) == "{" { var err error jrbody, err = jsonutils.Parse(rbody) if err != nil && debug { @@ -301,6 +301,9 @@ func ParseJSONResponse(resp *http.Response, err error, debug bool) (http.Header, if jrbody == nil { ce.Code = resp.StatusCode ce.Details = resp.Status + if len(rbody) > 0 { + ce.Details = string(rbody) + } return nil, nil, &ce }