This commit is contained in:
2025-11-02 20:33:28 +08:00
parent bb88c78c82
commit 2773c1a60b
13 changed files with 521 additions and 132 deletions

View File

@@ -120,11 +120,31 @@ func (w *WestDexService) CallAPI(ctx context.Context, code string, reqData map[s
// 设置请求头
req.Header.Set("Content-Type", "application/json")
// 发送请求
client := &http.Client{}
// 发送请求超时时间设置为60秒
client := &http.Client{
Timeout: 60 * time.Second,
}
httpResp, clientDoErr := client.Do(req)
if clientDoErr != nil {
err = errors.Join(ErrSystem, clientDoErr)
// 检查是否是超时错误
isTimeout := false
if ctx.Err() == context.DeadlineExceeded {
isTimeout = true
} else if netErr, ok := clientDoErr.(interface{ Timeout() bool }); ok && netErr.Timeout() {
isTimeout = true
} else if errStr := clientDoErr.Error();
errStr == "context deadline exceeded" ||
errStr == "timeout" ||
errStr == "Client.Timeout exceeded" ||
errStr == "net/http: request canceled" {
isTimeout = true
}
if isTimeout {
err = errors.Join(ErrDatasource, fmt.Errorf("API请求超时: %v", clientDoErr))
} else {
err = errors.Join(ErrSystem, clientDoErr)
}
if w.logger != nil {
w.logger.LogError(requestID, transactionID, code, err, reqData)
}
@@ -273,11 +293,31 @@ func (w *WestDexService) G05HZ01CallAPI(ctx context.Context, code string, reqDat
// 设置请求头
req.Header.Set("Content-Type", "application/json")
// 发送请求
client := &http.Client{}
// 发送请求超时时间设置为60秒
client := &http.Client{
Timeout: 60 * time.Second,
}
httpResp, clientDoErr := client.Do(req)
if clientDoErr != nil {
err = errors.Join(ErrSystem, clientDoErr)
// 检查是否是超时错误
isTimeout := false
if ctx.Err() == context.DeadlineExceeded {
isTimeout = true
} else if netErr, ok := clientDoErr.(interface{ Timeout() bool }); ok && netErr.Timeout() {
isTimeout = true
} else if errStr := clientDoErr.Error();
errStr == "context deadline exceeded" ||
errStr == "timeout" ||
errStr == "Client.Timeout exceeded" ||
errStr == "net/http: request canceled" {
isTimeout = true
}
if isTimeout {
err = errors.Join(ErrDatasource, fmt.Errorf("API请求超时: %v", clientDoErr))
} else {
err = errors.Join(ErrSystem, clientDoErr)
}
if w.logger != nil {
w.logger.LogError(requestID, transactionID, code, err, reqData)
}