fix(runtime-fallback): extract status code from nested AI SDK errors

AI SDK wraps HTTP status codes inside error.error.statusCode (e.g., AI_APICallError). The current extractStatusCode only checks the top level, missing these nested codes.

This caused runtime-fallback to skip retryable errors like 400, 500, 504 because it couldn't find the status code.

Fixes #2617
This commit is contained in:
Ravi Tharuma
2026-03-16 13:04:14 +01:00
parent 4759dfb654
commit 24a0f7b032

View File

@@ -33,7 +33,7 @@ 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
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") {
return statusCode
}