兼容响应数据非200没有响应Body的情况
This commit is contained in:
parent
42b9f26a9a
commit
0b2546217c
@ -14,6 +14,7 @@ import (
|
|||||||
"git.zhangdeman.cn/zhangdeman/network/httpclient/define"
|
"git.zhangdeman.cn/zhangdeman/network/httpclient/define"
|
||||||
"git.zhangdeman.cn/zhangdeman/serialize"
|
"git.zhangdeman.cn/zhangdeman/serialize"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -67,7 +68,11 @@ func (r *Response) fillResponseBody(reqCfg *define.Request, response *define.Res
|
|||||||
responseContentType := response.RestyResponse.Header().Get(consts.HeaderKeyContentType.String())
|
responseContentType := response.RestyResponse.Header().Get(consts.HeaderKeyContentType.String())
|
||||||
if responseContentType == "" {
|
if responseContentType == "" {
|
||||||
// 返回数据未说明 Content-Type
|
// 返回数据未说明 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], "/")
|
typeArr := strings.Split(strings.Split(responseContentType, ";")[0], "/")
|
||||||
responseType := "json"
|
responseType := "json"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user