兼容响应数据非200没有响应Body的情况

This commit is contained in:
白茶清欢 2025-05-29 23:16:17 +08:00
parent 42b9f26a9a
commit 0b2546217c

View File

@ -14,6 +14,7 @@ import (
"git.zhangdeman.cn/zhangdeman/network/httpclient/define"
"git.zhangdeman.cn/zhangdeman/serialize"
"github.com/tidwall/gjson"
"net/http"
"strings"
)
@ -67,7 +68,11 @@ func (r *Response) fillResponseBody(reqCfg *define.Request, response *define.Res
responseContentType := response.RestyResponse.Header().Get(consts.HeaderKeyContentType.String())
if responseContentType == "" {
// 返回数据未说明 Content-Type
return errors.New("response content type is empty")
if response.RestyResponse.StatusCode() != http.StatusOK {
responseContentType = "application/json"
} else {
return errors.New("response content type is empty")
}
}
typeArr := strings.Split(strings.Split(responseContentType, ";")[0], "/")
responseType := "json"