fix: httputils show error when resp body is not dict

This commit is contained in:
ioito
2019-08-19 21:34:58 +08:00
parent 1043958d0e
commit 1bc290d4a7
+4 -1
View File
@@ -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
}