|
@@ -82,20 +82,24 @@ func (hc *HttpClient) Post(url string, data interface{}) (resp *http.Response, e
|
|
|
logger.Error("创建POST请求失败: %v", err)
|
|
|
}
|
|
|
resp, err = hc.DoWithRetry(req.Context(), req)
|
|
|
- code := resp.StatusCode
|
|
|
- if code != 200 {
|
|
|
- logger.Error("请求错误应答,状态码:%d", code)
|
|
|
- errMsg := fmt.Sprintf("请求状态码异常,StatusCode:[%d]", code)
|
|
|
- respBody, respErr := io.ReadAll(resp.Body)
|
|
|
- if respErr != nil {
|
|
|
- logger.Error("读取body失败,err:%v", err)
|
|
|
+ if err == nil {
|
|
|
+ code := resp.StatusCode
|
|
|
+ if code != 200 {
|
|
|
+ logger.Error("请求错误应答,状态码:%d", code)
|
|
|
+ errMsg := fmt.Sprintf("请求状态码异常,StatusCode:[%d]", code)
|
|
|
+ respBody, respErr := io.ReadAll(resp.Body)
|
|
|
+ if respErr != nil {
|
|
|
+ logger.Error("读取body失败,err:%v", err)
|
|
|
+ err = errors.New(errMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ logger.Error("请求错误应答,body:%s", string(respBody))
|
|
|
+ errMsg = fmt.Sprintf("%s,body:%s", errMsg, string(respBody))
|
|
|
err = errors.New(errMsg)
|
|
|
return
|
|
|
}
|
|
|
- logger.Error("请求错误应答,body:%s", string(respBody))
|
|
|
- errMsg = fmt.Sprintf("%s,body:%s", errMsg, string(respBody))
|
|
|
- err = errors.New(errMsg)
|
|
|
- return
|
|
|
+ } else {
|
|
|
+ logger.Error("未知的应答错误,获取第三方授权信息失败")
|
|
|
}
|
|
|
return
|
|
|
}
|