mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:11:24 +00:00
fix(providers): include provider name in billing error messages (#14697)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 774e0b6605
Co-authored-by: fagemx <117356295+fagemx@users.noreply.github.com>
Co-authored-by: shakkernerd <165377636+shakkernerd@users.noreply.github.com>
Reviewed-by: @shakkernerd
This commit is contained in:
@@ -3,8 +3,15 @@ import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { FailoverReason } from "./types.js";
|
||||
import { formatSandboxToolPolicyBlockedMessage } from "../sandbox.js";
|
||||
|
||||
export const BILLING_ERROR_USER_MESSAGE =
|
||||
"⚠️ API provider returned a billing error — your API key has run out of credits or has an insufficient balance. Check your provider's billing dashboard and top up or switch to a different API key.";
|
||||
export function formatBillingErrorMessage(provider?: string): string {
|
||||
const providerName = provider?.trim();
|
||||
if (providerName) {
|
||||
return `⚠️ ${providerName} returned a billing error — your API key has run out of credits or has an insufficient balance. Check your ${providerName} billing dashboard and top up or switch to a different API key.`;
|
||||
}
|
||||
return "⚠️ API provider returned a billing error — your API key has run out of credits or has an insufficient balance. Check your provider's billing dashboard and top up or switch to a different API key.";
|
||||
}
|
||||
|
||||
export const BILLING_ERROR_USER_MESSAGE = formatBillingErrorMessage();
|
||||
|
||||
export function isContextOverflowError(errorMessage?: string): boolean {
|
||||
if (!errorMessage) {
|
||||
@@ -388,7 +395,7 @@ export function formatRawAssistantErrorForUi(raw?: string): string {
|
||||
|
||||
export function formatAssistantErrorText(
|
||||
msg: AssistantMessage,
|
||||
opts?: { cfg?: OpenClawConfig; sessionKey?: string },
|
||||
opts?: { cfg?: OpenClawConfig; sessionKey?: string; provider?: string },
|
||||
): string | undefined {
|
||||
// Also format errors if errorMessage is present, even if stopReason isn't "error"
|
||||
const raw = (msg.errorMessage ?? "").trim();
|
||||
@@ -450,7 +457,7 @@ export function formatAssistantErrorText(
|
||||
}
|
||||
|
||||
if (isBillingErrorMessage(raw)) {
|
||||
return BILLING_ERROR_USER_MESSAGE;
|
||||
return formatBillingErrorMessage(opts?.provider);
|
||||
}
|
||||
|
||||
if (isLikelyHttpErrorText(raw) || isRawApiErrorPayload(raw)) {
|
||||
|
||||
Reference in New Issue
Block a user