mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 13:11:10 +00:00
refactor(agents): share failover HTTP status classification (#36615)
* fix(agents): classify transient failover statuses consistently * fix(agents): preserve legacy failover status mapping
This commit is contained in:
@@ -251,6 +251,43 @@ export function isTransientHttpError(raw: string): boolean {
|
||||
return TRANSIENT_HTTP_ERROR_CODES.has(status.code);
|
||||
}
|
||||
|
||||
export function classifyFailoverReasonFromHttpStatus(
|
||||
status: number | undefined,
|
||||
message?: string,
|
||||
): FailoverReason | null {
|
||||
if (typeof status !== "number" || !Number.isFinite(status)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (status === 402) {
|
||||
return "billing";
|
||||
}
|
||||
if (status === 429) {
|
||||
return "rate_limit";
|
||||
}
|
||||
if (status === 401 || status === 403) {
|
||||
if (message && isAuthPermanentErrorMessage(message)) {
|
||||
return "auth_permanent";
|
||||
}
|
||||
return "auth";
|
||||
}
|
||||
if (status === 408) {
|
||||
return "timeout";
|
||||
}
|
||||
// Keep the status-only path conservative and behavior-preserving.
|
||||
// Message-path HTTP heuristics are broader and should not leak in here.
|
||||
if (status === 502 || status === 503 || status === 504) {
|
||||
return "timeout";
|
||||
}
|
||||
if (status === 529) {
|
||||
return "rate_limit";
|
||||
}
|
||||
if (status === 400) {
|
||||
return "format";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function stripFinalTagsFromText(text: string): string {
|
||||
if (!text) {
|
||||
return text;
|
||||
|
||||
Reference in New Issue
Block a user