fix: retry AI proxy with next proxy on HTTP errors too
Previously only retried on network errors (fetch exceptions). Now also rotates to next proxy when upstream returns non-2xx (429 rate limit, 5xx, etc). Applies to both OpenAI and Anthropic endpoints. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
38d7a83fe9
commit
2dfb87eac6
+14
-10
@@ -417,18 +417,22 @@ export async function handleAnthropicMessages(
|
||||
|
||||
try {
|
||||
response = await fetch(url, init);
|
||||
if (
|
||||
response.ok &&
|
||||
proxyPool &&
|
||||
proxyPool.size > 0 &&
|
||||
init.proxy &&
|
||||
attempt > 0
|
||||
) {
|
||||
proxyPool.markSuccess();
|
||||
if (response.ok) {
|
||||
// Success — reset proxy failure if we used one
|
||||
if (proxyPool && proxyPool.size > 0 && init.proxy && attempt > 0) {
|
||||
proxyPool.markSuccess();
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Non-2xx — mark proxy as failed so next attempt rotates
|
||||
if (proxyPool && proxyPool.size > 0 && init.proxy) {
|
||||
proxyPool.markFailed();
|
||||
}
|
||||
if (response.ok || response.status < 500) break;
|
||||
} catch {
|
||||
// fall through to next attempt
|
||||
// Network error — mark proxy as failed, retry
|
||||
if (proxyPool && proxyPool.size > 0 && init.proxy) {
|
||||
proxyPool.markFailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user