fix(antigravity): 429 时也切换 URL 重试
- 429 优先切换到下一个 URL 重试 - 只有所有 URL 都返回 429 时才限流账户并返回错误 - 与 client.go 中的逻辑保持一致
This commit is contained in:
@@ -591,11 +591,19 @@ urlFallbackLoop:
|
||||
return nil, s.writeClaudeError(c, http.StatusBadGateway, "upstream_error", "Upstream request failed after retries")
|
||||
}
|
||||
|
||||
// 429 不重试,直接限流账户
|
||||
// 429 限流:优先切换 URL,所有 URL 都 429 时才返回
|
||||
if resp.StatusCode == http.StatusTooManyRequests {
|
||||
respBody, _ := io.ReadAll(io.LimitReader(resp.Body, 2<<20))
|
||||
_ = resp.Body.Close()
|
||||
|
||||
// 还有其他 URL,切换重试
|
||||
if urlIdx < len(availableURLs)-1 {
|
||||
antigravity.DefaultURLAvailability.MarkUnavailable(baseURL)
|
||||
log.Printf("%s URL fallback (429): %s -> %s", prefix, baseURL, availableURLs[urlIdx+1])
|
||||
continue urlFallbackLoop
|
||||
}
|
||||
|
||||
// 所有 URL 都 429,限流账户并返回
|
||||
s.handleUpstreamError(ctx, prefix, account, resp.StatusCode, resp.Header, respBody, quotaScope)
|
||||
log.Printf("%s status=429 rate_limited body=%s", prefix, truncateForLog(respBody, 200))
|
||||
resp = &http.Response{
|
||||
@@ -1144,11 +1152,19 @@ urlFallbackLoop:
|
||||
return nil, s.writeGoogleError(c, http.StatusBadGateway, "Upstream request failed after retries")
|
||||
}
|
||||
|
||||
// 429 不重试,直接限流账户
|
||||
// 429 限流:优先切换 URL,所有 URL 都 429 时才返回
|
||||
if resp.StatusCode == http.StatusTooManyRequests {
|
||||
respBody, _ := io.ReadAll(io.LimitReader(resp.Body, 2<<20))
|
||||
_ = resp.Body.Close()
|
||||
|
||||
// 还有其他 URL,切换重试
|
||||
if urlIdx < len(availableURLs)-1 {
|
||||
antigravity.DefaultURLAvailability.MarkUnavailable(baseURL)
|
||||
log.Printf("%s URL fallback (429): %s -> %s", prefix, baseURL, availableURLs[urlIdx+1])
|
||||
continue urlFallbackLoop
|
||||
}
|
||||
|
||||
// 所有 URL 都 429,限流账户并返回
|
||||
s.handleUpstreamError(ctx, prefix, account, resp.StatusCode, resp.Header, respBody, quotaScope)
|
||||
log.Printf("%s status=429 rate_limited body=%s", prefix, truncateForLog(respBody, 200))
|
||||
resp = &http.Response{
|
||||
|
||||
Reference in New Issue
Block a user