// public-error-text (F39): what an upstream error may show the browser. Business messages and codes ("Member code is // required.", "KYC_REQUIRED") pass; anything that carries internal detail (URLs, hostnames, Java class or exception // names, stack frames, SQL, HTML error pages, very long text) becomes one generic message. The raw text is never sent // to the client; callers log only the status and path, never the text (it can hold personal data). export const GENERIC_ERROR = "Something went wrong. Please try again."; const MAX_LENGTH = 300; const INTERNAL_MARKERS: readonly RegExp[] = [ /[a-z][a-z0-9+.-]*:\/\//i, // any URL (http://service-counter-v1/...) /\.svc\b|\.cluster\.local\b|\.internal\b|\blocalhost\b/i, // in-cluster hostnames /\b(?:java|javax|jakarta|org|com|io|net)\.[a-z0-9_]+\.[A-Za-z0-9_.$]+/, // qualified class names /\b[A-Z][A-Za-z0-9]*(?:Exception|Error)\b/, // NullPointerException, HttpServerErrorException /\bat [a-z0-9_.$]+\([A-Za-z0-9_]+\.java:\d+\)/i, // stack frames /\b(?:SQL|JDBC|Hibernate|could not execute|constraint \[|I\/O error|Connection refused|Whitelabel)\b/i, /<\s*(?:!doctype|html|body|head)\b/i, // HTML error pages /[\r\n]/, // multi-line text (stack traces) ]; export function publicError(text: string | undefined | null): string { if (typeof text !== "string") return GENERIC_ERROR; const trimmed = text.trim(); if (!trimmed || text.length > MAX_LENGTH) return GENERIC_ERROR; return INTERNAL_MARKERS.some(re => re.test(text)) ? GENERIC_ERROR : text; }