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

Function extractStatus

packages/providers/src/retry.ts:175–194  ·  view source on GitHub ↗
(err: unknown)

Source from the content-addressed store, hash-verified

173}
174
175function extractStatus(err: unknown): number | undefined {
176 if (typeof err !== 'object' || err === null) return undefined;
177 const candidates = [
178 (err as { status?: unknown }).status,
179 (err as { statusCode?: unknown }).statusCode,
180 (err as { response?: { status?: unknown } }).response?.status,
181 ];
182 for (const c of candidates) {
183 if (typeof c === 'number' && Number.isFinite(c)) return c;
184 }
185 // CodesignError messages may embed the status: "HTTP 503 …"
186 if (err instanceof CodesignError) {
187 const m = /\b(\d{3})\b/.exec(err.message);
188 if (m?.[1]) {
189 const n = Number(m[1]);
190 if (n >= 400 && n < 600) return n;
191 }
192 }
193 return undefined;
194}
195
196function extractRetryAfterMs(err: unknown): number | undefined {
197 if (typeof err !== 'object' || err === null) return undefined;

Callers 1

classifyErrorFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected