You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
692 B
23 lines
692 B
import type { TranslationKey } from "@/i18n";
|
|
|
|
type Translate = (key: TranslationKey, values?: Record<string, string | number>) => string;
|
|
|
|
const PROVIDER_OVERLOADED_RE =
|
|
/^(.*?): provider is temporarily overloaded\. Please retry in a moment or switch models\.$/i;
|
|
|
|
export function formatUserFacingError(
|
|
message: string | null | undefined,
|
|
t: Translate,
|
|
modelDisplayName?: string | null
|
|
): string | null {
|
|
if (!message) return null;
|
|
|
|
const overloadedMatch = message.match(PROVIDER_OVERLOADED_RE);
|
|
if (overloadedMatch) {
|
|
return t("error.providerOverloaded", {
|
|
model: modelDisplayName?.trim() || (overloadedMatch[1] ?? "Model").trim(),
|
|
});
|
|
}
|
|
|
|
return message;
|
|
}
|
|
|