mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:01:25 +00:00
refactor(agents): dedupe transient error copy (#16324)
This commit is contained in:
committed by
GitHub
parent
3e6d1e9cf8
commit
d714ac7797
@@ -14,6 +14,18 @@ export function formatBillingErrorMessage(provider?: string): string {
|
||||
export const BILLING_ERROR_USER_MESSAGE = formatBillingErrorMessage();
|
||||
|
||||
const RATE_LIMIT_ERROR_USER_MESSAGE = "⚠️ API rate limit reached. Please try again later.";
|
||||
const OVERLOADED_ERROR_USER_MESSAGE =
|
||||
"The AI service is temporarily overloaded. Please try again in a moment.";
|
||||
|
||||
function formatRateLimitOrOverloadedErrorCopy(raw: string): string | undefined {
|
||||
if (isRateLimitErrorMessage(raw)) {
|
||||
return RATE_LIMIT_ERROR_USER_MESSAGE;
|
||||
}
|
||||
if (isOverloadedErrorMessage(raw)) {
|
||||
return OVERLOADED_ERROR_USER_MESSAGE;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function isContextOverflowError(errorMessage?: string): boolean {
|
||||
if (!errorMessage) {
|
||||
@@ -463,12 +475,9 @@ export function formatAssistantErrorText(
|
||||
return `LLM request rejected: ${invalidRequest[1]}`;
|
||||
}
|
||||
|
||||
if (isRateLimitErrorMessage(raw)) {
|
||||
return RATE_LIMIT_ERROR_USER_MESSAGE;
|
||||
}
|
||||
|
||||
if (isOverloadedErrorMessage(raw)) {
|
||||
return "The AI service is temporarily overloaded. Please try again in a moment.";
|
||||
const transientCopy = formatRateLimitOrOverloadedErrorCopy(raw);
|
||||
if (transientCopy) {
|
||||
return transientCopy;
|
||||
}
|
||||
|
||||
if (isBillingErrorMessage(raw)) {
|
||||
@@ -523,11 +532,9 @@ export function sanitizeUserFacingText(text: string, opts?: { errorContext?: boo
|
||||
}
|
||||
|
||||
if (ERROR_PREFIX_RE.test(trimmed)) {
|
||||
if (isRateLimitErrorMessage(trimmed)) {
|
||||
return RATE_LIMIT_ERROR_USER_MESSAGE;
|
||||
}
|
||||
if (isOverloadedErrorMessage(trimmed)) {
|
||||
return "The AI service is temporarily overloaded. Please try again in a moment.";
|
||||
const prefixedCopy = formatRateLimitOrOverloadedErrorCopy(trimmed);
|
||||
if (prefixedCopy) {
|
||||
return prefixedCopy;
|
||||
}
|
||||
if (isTimeoutErrorMessage(trimmed)) {
|
||||
return "LLM request timed out.";
|
||||
|
||||
Reference in New Issue
Block a user