Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
ac7503d9
Commit
ac7503d9
authored
Jan 17, 2026
by
song
Browse files
fix(antigravity): 429 时也切换 URL 重试
- 429 优先切换到下一个 URL 重试 - 只有所有 URL 都返回 429 时才限流账户并返回错误 - 与 client.go 中的逻辑保持一致
parent
69c4b17a
Changes
1
Show whitespace changes
Inline
Side-by-side
backend/internal/service/antigravity_gateway_service.go
View file @
ac7503d9
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment