状态码判断
This commit is contained in:
parent
0980531019
commit
5b41563619
27
client.go
27
client.go
@ -183,9 +183,16 @@ func (hc *HttpClient) Request() *define.Response {
|
||||
continue
|
||||
}
|
||||
// 解析返回信息
|
||||
|
||||
// 设置缓存
|
||||
response.IsCache, response.CacheError = hc.setCacheResult(response)
|
||||
hc.fillResponseHeader(response)
|
||||
hc.fillResponseCookie(response)
|
||||
hc.fillResponseBody(response)
|
||||
if !hc.isCodeSuccess(response) {
|
||||
time.Sleep(time.Duration(hc.reqConfig.RetryRule.RetryTimeInterval) * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
response.IsSuccess = true //设置成功
|
||||
response.IsCache, response.CacheError = hc.setCacheResult(response) // 设置缓存
|
||||
break
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -270,6 +277,20 @@ func (hc *HttpClient) fillResponseBody(response *define.Response) {
|
||||
})
|
||||
}
|
||||
|
||||
// isHttpCodeSuccess ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 22:48 2024/6/6
|
||||
func (hc *HttpClient) isCodeSuccess(response *define.Response) bool {
|
||||
for _, itemSuccessCode := range hc.reqConfig.SuccessCodeList {
|
||||
if itemSuccessCode == response.Code {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// getCacheResult 获取缓存结果
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
|
Loading…
Reference in New Issue
Block a user