fix(model-fallback): add HTTP statusCode check for GLM rate limit fallback
isRetryableModelError() now checks the HTTP status code (429/503/529) in addition to existing message pattern matching. This ensures rate limit errors trigger model fallback regardless of error message format or language (e.g., Chinese GLM errors). Changes: - ErrorInfo interface extended with statusCode?: number - isRetryableModelError() checks statusCode after STOP patterns, before message pattern fallback - extractErrorStatusCode() added to error-classifier.ts (supports statusCode, status, code, response.status fields) - GLM-specific STOP patterns added: daily call limit, in arrears, fair use policy, recharge and try — these prevent quota/billing 429s from being treated as transient rate limits - statusCode propagated through tryFallbackRetry and manager.ts 400 intentionally excluded from statusCode check (permanent client error).
This commit is contained in:
@@ -65,6 +65,33 @@ export function extractErrorMessage(error: unknown): string | undefined {
|
||||
}
|
||||
}
|
||||
|
||||
export function extractErrorStatusCode(error: unknown): number | undefined {
|
||||
if (!isRecord(error)) return undefined
|
||||
|
||||
for (const key of ["statusCode", "status", "code"]) {
|
||||
const val = (error as Record<string, unknown>)[key]
|
||||
if (typeof val === "number" && val >= 100 && val < 600) return val
|
||||
}
|
||||
|
||||
const statusVal = (error as Record<string, unknown>)["status"]
|
||||
if (typeof statusVal === "string") {
|
||||
const parsed = parseInt(statusVal, 10)
|
||||
if (parsed >= 100 && parsed < 600) return parsed
|
||||
}
|
||||
|
||||
const responseRaw = (error as Record<string, unknown>)["response"]
|
||||
if (isRecord(responseRaw)) {
|
||||
const respStatus = responseRaw["status"]
|
||||
if (typeof respStatus === "number" && respStatus >= 100 && respStatus < 600) return respStatus
|
||||
if (typeof respStatus === "string") {
|
||||
const parsed = parseInt(respStatus, 10)
|
||||
if (parsed >= 100 && parsed < 600) return parsed
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
interface EventPropertiesLike {
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user