🚫 sanitize unmapped error messages — no raw backend text leak
Browse files at this commit7a1b27ecc9d0df378045ef743a4e73c51564870bParent: e3c3889- fix
- 🚫 sanitize unmapped error messages — no raw backend text leak
2 changed files +15 -7
src/api/__tests__/client/client.test.tsmodified+9 -5
| @@ -242,9 +242,13 @@ describe("client", () => { | ||
| 242 | 242 | ).toBe("Bu sınava yalnızca dersin öğretmenleri veya bir müdür soru ekleyebilir."); |
| 243 | 243 | }); |
| 244 | 244 | |
| 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 | + ); | |
| 248 | 252 | }); |
| 249 | 253 | |
| 250 | 254 | it("localizes backend max-length validation messages", () => { |
| @@ -330,8 +334,8 @@ describe("client", () => { | ||
| 330 | 334 | }); |
| 331 | 335 | |
| 332 | 336 | 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."); | |
| 335 | 339 | }); |
| 336 | 340 | |
| 337 | 341 | 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 | ||
| 477 | 477 | if (runtime) return runtime; |
| 478 | 478 | const validation = formatValidationMessage(message, locale); |
| 479 | 479 | 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."; | |
| 482 | 486 | } |
| 483 | 487 | |
| 484 | 488 | export function formatApiError(err: unknown, locale: Locale = currentLocale()): string { |