fix(runtime-fallback): prefer numeric status codes over non-numeric in extraction chain
The nullish-coalescing chain could stop at a non-numeric value (e.g. status: "error"), preventing deeper nested numeric statusCode values from being reached. Switch to Array.find() with a type guard to always select the first numeric value. Adds 11 tests for extractStatusCode covering: top-level, nested (data/error/cause), non-numeric skip, fallback to regex, and precedence. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -33,8 +33,15 @@ export function extractStatusCode(error: unknown, retryOnErrors?: number[]): num
|
||||
|
||||
const errorObj = error as Record<string, unknown>
|
||||
|
||||
const statusCode = errorObj.statusCode ?? errorObj.status ?? (errorObj.data as Record<string, unknown>)?.statusCode ?? (errorObj.error as Record<string, unknown>)?.statusCode ?? (errorObj.cause as Record<string, unknown>)?.statusCode
|
||||
if (typeof statusCode === "number") {
|
||||
const statusCode = [
|
||||
errorObj.statusCode,
|
||||
errorObj.status,
|
||||
(errorObj.data as Record<string, unknown>)?.statusCode,
|
||||
(errorObj.error as Record<string, unknown>)?.statusCode,
|
||||
(errorObj.cause as Record<string, unknown>)?.statusCode,
|
||||
].find((code): code is number => typeof code === "number")
|
||||
|
||||
if (statusCode !== undefined) {
|
||||
return statusCode
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user