mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 13:00:45 +00:00
fix(agents): recognize flat JSON billing payloads and snake_case error codes (#74188)
* fix(agents): recognize flat JSON billing payloads and snake_case error codes
Two independent fixes for billing error detection:
1. isErrorPayloadObject/parseApiErrorInfo now recognize flat JSON like
{"error":"string_code","message":"..."} where error is a string code
at the top level, not just nested {"error":{"type":"...","message":"..."}}
envelopes.
2. isBillingErrorMessage now matches "insufficient_balance" (underscore)
and "Insufficient MBT balance" (one word between insufficient/balance)
via two new patterns in the billing pattern list.
Together these prevent raw JSON from leaking to user-facing chat when
providers return 402-style flat payloads.
Fixes #74079
* fix(agents): remove redundant billing pattern and fix misleading regex comment
This commit is contained in:
@@ -47,6 +47,10 @@ function isErrorPayloadObject(payload: unknown): payload is ErrorPayload {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Flat error payloads: {"error":"insufficient_balance","message":"..."}
|
||||
if (typeof err === "string" && typeof record.message === "string") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -165,6 +169,9 @@ export function parseApiErrorInfo(raw?: string): ApiErrorInfo | null {
|
||||
if (typeof err.message === "string") {
|
||||
errMessage = err.message;
|
||||
}
|
||||
} else if (typeof payload.error === "string") {
|
||||
// Flat error payloads: {"error":"insufficient_balance","message":"..."}
|
||||
errType = payload.error;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user