返回值增加http状态码验证

This commit is contained in:
白茶清欢 2024-06-09 19:56:32 +08:00
parent 2a542063f0
commit bab271d562
1 changed files with 13 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import (
"git.zhangdeman.cn/zhangdeman/serialize"
"github.com/go-resty/resty/v2"
"github.com/tidwall/gjson"
"net/http"
"strings"
"time"
)
@ -187,7 +188,19 @@ func (hc *HttpClient) Request() *define.Response {
hc.fillResponseHeader(response)
hc.fillResponseCookie(response)
hc.fillResponseBody(response)
if response.HttpCode != http.StatusOK {
response.FailInfo = &define.ResponseFailInfo{
Type: define.RequestFailTypeServerError,
Message: "http code is " + response.HttpCodeStatus + ", not success",
}
time.Sleep(time.Duration(hc.reqConfig.RetryRule.RetryTimeInterval) * time.Millisecond)
continue
}
if !hc.isCodeSuccess(response) {
response.FailInfo = &define.ResponseFailInfo{
Type: define.RequestFailTypeBusinessError,
Message: "business code is " + response.Code + ", not success",
}
time.Sleep(time.Duration(hc.reqConfig.RetryRule.RetryTimeInterval) * time.Millisecond)
continue
}