From 4e20cbb4d6f70d62b0bcfce3abffa47a9e55b94c Mon Sep 17 00:00:00 2001 From: Huang-404-Q <129407632+Huang-404-Q@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:03:17 +0800 Subject: [PATCH] fix(uploads): treat a missing message as an empty one (#7342) The unsuccessful-upload branch called result.message.trim() directly. A gateway or proxy that omits message turns a handled upload failure into a TypeError while handling it, losing the clean "Upload failed" path. Coerce a non-string message to an empty string before trimming. The regression test sends success:false without a message and expects "Upload failed"; it throws a TypeError on main. Co-authored-by: Willem Jiang --- frontend/src/core/uploads/api.ts | 5 ++++- frontend/tests/unit/core/uploads/api.test.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/frontend/src/core/uploads/api.ts b/frontend/src/core/uploads/api.ts index 501cfe8c04..769f314979 100644 --- a/frontend/src/core/uploads/api.ts +++ b/frontend/src/core/uploads/api.ts @@ -147,7 +147,10 @@ export async function uploadFiles( const result = (await response.json()) as UploadResponse; if (result.success === false) { - const message = result.message.trim(); + // A gateway or proxy may omit `message`; treat it like an empty one + // instead of throwing a TypeError while handling the failure. + const message = + typeof result.message === "string" ? result.message.trim() : ""; throw new Error( message ? `Upload incomplete: ${message}` : "Upload failed", ); diff --git a/frontend/tests/unit/core/uploads/api.test.ts b/frontend/tests/unit/core/uploads/api.test.ts index 105d307e7d..7b7fe19d6f 100644 --- a/frontend/tests/unit/core/uploads/api.test.ts +++ b/frontend/tests/unit/core/uploads/api.test.ts @@ -94,6 +94,18 @@ describe("uploads api", () => { expect(error.message).toBe("Upload failed"); }); + test("uses the upload fallback when an unsuccessful response omits the message", async () => { + const error = await uploadError( + jsonResponse(200, { + success: false, + files: [], + skipped_files: ["report.pdf"], + }), + ); + + expect(error.message).toBe("Upload failed"); + }); + test("preserves string error details", async () => { const error = await uploadError( jsonResponse(413, { detail: "File exceeds the upload limit" }),