MCPcopy
hub / github.com/OpenCoworkAI/open-codesign / classifyByStatus

Function classifyByStatus

packages/providers/src/retry.ts:61–85  ·  view source on GitHub ↗
(status: number, err: unknown, wire?: WireApi)

Source from the content-addressed store, hash-verified

59]);
60
61function 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
87function normalizeErrorText(errorMessage: string): string {
88 let out = '';

Callers 1

classifyErrorFunction · 0.85

Calls 2

extractRetryAfterMsFunction · 0.85

Tested by

no test coverage detected