fix: suppress Claude 502 provider errors from chat output

This commit is contained in:
Eyejoker
2026-03-26 10:11:24 +09:00
parent bba19b0c0f
commit a330ebdf2a
7 changed files with 239 additions and 2 deletions

View File

@@ -54,6 +54,32 @@ export function isClaudeAuthExpiredMessage(text: string): boolean {
);
}
export function detectClaudeProviderFailureMessage(
text: string,
): Extract<AgentTriggerReason, '429' | 'overloaded' | 'network-error'> | '' {
const normalized = text.trim().toLowerCase().replace(/\s+/g, ' ');
const looksLikeProviderError =
normalized.startsWith('api error:') ||
normalized.startsWith('error: api error:') ||
normalized.startsWith('network error') ||
normalized.startsWith('fetch failed');
if (!looksLikeProviderError) {
return '';
}
const classification = classifyAgentError(text);
if (
classification.category === 'rate-limit' ||
classification.category === 'overloaded' ||
classification.category === 'network-error'
) {
return classification.reason;
}
return '';
}
export function isClaudeOrgAccessDeniedMessage(text: string): boolean {
const normalized = text.trim().toLowerCase().replace(/\s+/g, ' ');
const hasOrgAccessDeniedMarker = normalized.includes(
@@ -192,7 +218,14 @@ export function classifyAgentError(
}
// 503 / Overloaded
if (lower.includes('503') || lower.includes('overloaded')) {
if (
lower.includes('503') ||
lower.includes('overloaded') ||
((lower.includes('502') || lower.includes('bad gateway')) &&
(lower.includes('cloudflare') ||
lower.includes('<html') ||
lower.includes('api error')))
) {
return { category: 'overloaded', reason: 'overloaded' };
}