feat 请求超时返回错误

This commit is contained in:
timerzz 2024-05-30 21:32:09 +08:00
parent 53c6ee15ff
commit 38f473928f

View File

@ -2,6 +2,7 @@ package coach_client
import ( import (
"context" "context"
"fmt"
"gitea.timerzz.com/kedaya_haitao/common/pkg/proxy" "gitea.timerzz.com/kedaya_haitao/common/pkg/proxy"
restry_pool "gitea.timerzz.com/kedaya_haitao/common/pkg/restry-pool" restry_pool "gitea.timerzz.com/kedaya_haitao/common/pkg/restry-pool"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
@ -27,6 +28,9 @@ func tryRequest(ctx context.Context, urlPath string, respData any, proxyGetter f
for p := proxyGetter(); p != nil; p = proxyGetter() { for p := proxyGetter(); p != nil; p = proxyGetter() {
select { select {
case <-ctx.Done(): case <-ctx.Done():
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return fmt.Errorf("超时未获取到结果,链接:%s", urlPath)
}
return nil return nil
default: default: