| 173 | } |
| 174 | |
| 175 | function 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 | |
| 196 | function extractRetryAfterMs(err: unknown): number | undefined { |
| 197 | if (typeof err !== 'object' || err === null) return undefined; |