fix(errors): hide internal agent metadata

This commit is contained in:
t8y2 committed 2026-08-03 13:56:18 +08:00
1 parent fa17c01c3b
commit 16920188ee
5 files changed
+65 -15

No files matched your search

+5 -5
View File
@@ -1,4 +1,4 @@
import { normalizeBackendError, type BackendError } from "@/lib/backend/errorUtils";
import { normalizeBackendError, sanitizeBackendErrorMessage, type BackendError } from "@/lib/backend/errorUtils";
/**
* Minimal shape of a translate function, satisfied by both `useI18n().t` inside
@@ -115,15 +115,15 @@ const paramNames: Record<string, string | string[]> = {
};
function backendErrorMessage(error: unknown): string {
if (typeof error === "string") return error;
if (error && typeof error === "object" && "message" in error && typeof error.message === "string") return error.message;
return String(error);
if (typeof error === "string") return sanitizeBackendErrorMessage(error);
if (error && typeof error === "object" && "message" in error && typeof error.message === "string") return sanitizeBackendErrorMessage(error.message);
return sanitizeBackendErrorMessage(String(error));
}
function translateStructuredBackendError(t: BackendErrorTranslate, error: BackendError): string {
const translated = t(error.messageKey, error.messageParams);
const summary = translated !== error.messageKey ? translated : t("backendErrors.unknown");
const detail = error.detail?.trim();
const detail = error.detail ? sanitizeBackendErrorMessage(error.detail).trim() : undefined;
return detail && detail !== summary ? `${summary}\n\n${detail}` : summary;
}