细化http request错误分类
This commit is contained in:
@ -270,9 +270,14 @@ func (hc *HttpClient) requestBackendApi() *define.Response {
|
||||
response.Seq++
|
||||
response.RequestCount++
|
||||
if response.RestyResponse, err = hc.request.Send(); nil != err {
|
||||
errType := define.RequestFailTypeSend
|
||||
if strings.Contains(strings.ToLower(err.Error()), "client.timeout exceeded while awaiting headers") {
|
||||
// 请求超时
|
||||
errType = define.RequestFailTypeTimeoutError
|
||||
}
|
||||
response.FailInfo = &define.ResponseFailInfo{
|
||||
Type: define.RequestFailTypeSend,
|
||||
Message: "response instance is nil",
|
||||
Type: errType,
|
||||
Message: err.Error(),
|
||||
}
|
||||
time.Sleep(time.Duration(hc.reqConfig.RetryRule.RetryTimeInterval) * time.Millisecond)
|
||||
continue
|
||||
@ -291,8 +296,13 @@ func (hc *HttpClient) requestBackendApi() *define.Response {
|
||||
hc.fillResponseCookie(response)
|
||||
hc.fillResponseBody(response)
|
||||
if response.HttpCode != http.StatusOK {
|
||||
errType := define.RequestFailTypeServerError
|
||||
if response.HttpCode/100 == 4 {
|
||||
// 客户端错误
|
||||
errType = define.RequestFailTypeClientRequestInvalidError
|
||||
}
|
||||
response.FailInfo = &define.ResponseFailInfo{
|
||||
Type: define.RequestFailTypeServerError,
|
||||
Type: errType,
|
||||
Message: "http code is " + response.HttpCodeStatus + ", not success",
|
||||
}
|
||||
time.Sleep(time.Duration(hc.reqConfig.RetryRule.RetryTimeInterval) * time.Millisecond)
|
||||
|
@ -64,8 +64,9 @@ type ResponseCacheInfo struct {
|
||||
}
|
||||
|
||||
const (
|
||||
RequestFailTypeSend = "SEND_REQUEST_FAIL" // 发送请求即失败, 问题出现在客户端
|
||||
RequestFailTypeClientError = "CLIENT_REQUEST_ERROR" // 请求失败, 原因出在客户端, 对应http code 4xx
|
||||
RequestFailTypeServerError = "SERVER_DEAL_ERROR" // 服务端处理失败, 对应 http code 5xx
|
||||
RequestFailTypeBusinessError = "SERVICE_BUSINESS_ERROR" // 返回状态码为200, 但是业务状态码非成功
|
||||
RequestFailTypeSend = "SEND_REQUEST_FAIL" // 发送请求即失败, 问题出现在客户端
|
||||
RequestFailTypeClientRequestInvalidError = "CLIENT_REQUEST_INVALID" // 请求非法
|
||||
RequestFailTypeTimeoutError = "CLIENT_REQUEST_TIMEOUT_ERROR" // 请求失败, 请求超时
|
||||
RequestFailTypeServerError = "SERVER_DEAL_ERROR" // 服务端处理失败, 对应 http code 5xx
|
||||
RequestFailTypeBusinessError = "SERVICE_BUSINESS_ERROR" // 返回状态码为200, 但是业务状态码非成功
|
||||
)
|
||||
|
Reference in New Issue
Block a user