mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-10-26 13:16:24 +00:00
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 <willem.jiang@gmail.com>
This commit is contained in:
parent
e7d96fe051
commit
4e20cbb4d6
@ -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",
|
||||
);
|
||||
|
||||
@ -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" }),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user