fix(errors): hide internal agent metadata
This commit is contained in:
5 files changed
+65
-15
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user