(status: number, err: unknown, wire?: WireApi)
| 59 | ]); |
| 60 | |
| 61 | function classifyByStatus(status: number, err: unknown, wire?: WireApi): RetryDecision | undefined { |
| 62 | if (status === 429) { |
| 63 | const retryAfterMs = extractRetryAfterMs(err); |
| 64 | const decision: RetryDecision = { retry: true, reason: 'rate-limited (429)' }; |
| 65 | if (retryAfterMs !== undefined) decision.retryAfterMs = retryAfterMs; |
| 66 | return decision; |
| 67 | } |
| 68 | if (status >= 500 && status <= 599) { |
| 69 | // Third-party Anthropic relays (sub2api, claude2api, anyrouter…) often |
| 70 | // return 5xx + "not implemented" for POST /v1/messages even though their |
| 71 | // /v1/models endpoint works. Retrying wastes 3 rounds of exponential |
| 72 | // backoff on an endpoint that will never respond; short-circuit so the |
| 73 | // user sees the actionable error immediately. Only applies to |
| 74 | // anthropic-wire endpoints — OpenAI/Google wires can emit the same text |
| 75 | // for unrelated reasons and should retry normally. |
| 76 | if (wire === 'anthropic' && looksLikeGatewayMissingMessagesApi(err)) { |
| 77 | return { retry: false, reason: 'gateway does not implement Messages API' }; |
| 78 | } |
| 79 | return { retry: true, reason: `server error (${status})` }; |
| 80 | } |
| 81 | if (status >= 400 && status <= 499) { |
| 82 | return { retry: false, reason: `client error (${status})` }; |
| 83 | } |
| 84 | return undefined; |
| 85 | } |
| 86 | |
| 87 | function normalizeErrorText(errorMessage: string): string { |
| 88 | let out = ''; |
no test coverage detected