Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
27 lines
1.5 KiB
TypeScript
27 lines
1.5 KiB
TypeScript
// 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;
|
|
}
|