From 7c2268417bfec64dc4a1f8c4ce338caea3cee08d Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Thu, 30 Jul 2020 11:30:38 +0800 Subject: [PATCH] fix: avoid parse json err nil pointer --- pkg/util/httputils/httputils.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/util/httputils/httputils.go b/pkg/util/httputils/httputils.go index 6ef0d42cfd..b60ac60aa9 100644 --- a/pkg/util/httputils/httputils.go +++ b/pkg/util/httputils/httputils.go @@ -660,12 +660,14 @@ func ParseJSONResponse(resp *http.Response, err error, debug bool) (http.Header, jrbody2 = v } } - if ecode, _ := jrbody2.GetString("code"); len(ecode) > 0 { - code, err := strconv.Atoi(ecode) - if err != nil { - ce.Class = ecode - } else { - ce.Code = code + if jrbody2 != nil { + if ecode, _ := jrbody2.GetString("code"); len(ecode) > 0 { + code, err := strconv.Atoi(ecode) + if err != nil { + ce.Class = ecode + } else { + ce.Code = code + } } } if ce.Code == 0 {