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:
MythEclipse
2026-06-10 23:57:24 +07:00
co-authored by Claude Fable 5
parent 38d7a83fe9
commit 2dfb87eac6
2 changed files with 28 additions and 14 deletions
+14 -10
View File
@@ -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();
}
}
}