From 598e8a9248488ec6a082750782eaeaa6caeb14ab 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 093910865e..024fc4d105 100644 --- a/pkg/util/httputils/httputils.go +++ b/pkg/util/httputils/httputils.go @@ -767,12 +767,14 @@ func ParseJSONResponse(reqBody string, resp *http.Response, err error, debug boo 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 {