forge
Explore
Log in

Don't you dare go Hollow

🚫 sanitize unmapped error messages — no raw backend text leak

Browse files at this commit

7a1b27ecc9d0df378045ef743a4e73c51564870bBurak BoduroğluParent: e3c3889
  • fix
    • 🚫 sanitize unmapped error messages — no raw backend text leak
Show full message
fix(api): 🚫 sanitize unmapped error messages — no raw backend text leak

- replace sentenceCase fallback with safe localized generic
- avoids exposing raw English/technical backend errors to users
- update tests to match new messages
src/api/__tests__/client/client.test.tsmodified+9 -5
@@ -242,9 +242,13 @@ describe("client", () => {
242242 ).toBe("Bu sınava yalnızca dersin öğretmenleri veya bir müdür soru ekleyebilir.");
243243 });
244244
245- it("handles unknown messages with sentence case", () => {
246- expect(formatApiErrorMessage("custom error occurred", "en")).toBe("Custom error occurred");
247- expect(formatApiErrorMessage("custom error occurred", "tr")).toBe("İşlem tamamlanamadı: Custom error occurred");
245+ it("falls back to a clean localized message for unmapped errors (no raw leak)", () => {
246+ expect(formatApiErrorMessage("custom error occurred", "en")).toBe(
247+ "Something went wrong. Please check your input and try again.",
248+ );
249+ expect(formatApiErrorMessage("custom error occurred", "tr")).toBe(
250+ "İşlem tamamlanamadı. Lütfen bilgileri kontrol edip tekrar dene.",
251+ );
248252 });
249253
250254 it("localizes backend max-length validation messages", () => {
@@ -330,8 +334,8 @@ describe("client", () => {
330334 });
331335
332336 it("formats generic Error", () => {
333- expect(formatApiError(new Error("generic"), "en")).toBe("Generic");
334- expect(formatApiError(new Error("generic"), "tr")).toBe("İşlem tamamlanamadı: Generic");
337+ expect(formatApiError(new Error("generic"), "en")).toBe("Something went wrong. Please check your input and try again.");
338+ expect(formatApiError(new Error("generic"), "tr")).toBe("İşlem tamamlanamadı. Lütfen bilgileri kontrol edip tekrar dene.");
335339 });
336340
337341 it("does not expose network, runtime, or provider errors to users", () => {
src/api/client/client.tsmodified+6 -2
@@ -477,8 +477,12 @@ export function formatApiErrorMessage(message: string, locale: Locale = currentL
477477 if (runtime) return runtime;
478478 const validation = formatValidationMessage(message, locale);
479479 if (validation) return validation;
480- if (locale === "tr") return `İşlem tamamlanamadı: ${sentenceCase(message)}`;
481- return sentenceCase(message);
480+ // Unmapped backend text is raw English/technical — never surface it to the
481+ // user. Fall back to a clean localized line; add a mapping in
482+ // API_ERROR_MESSAGES when a specific message deserves its own wording.
483+ return locale === "tr"
484+ ? "İşlem tamamlanamadı. Lütfen bilgileri kontrol edip tekrar dene."
485+ : "Something went wrong. Please check your input and try again.";
482486 }
483487
484488 export function formatApiError(err: unknown, locale: Locale = currentLocale()): string {