mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-19 12:24:46 +08:00
fix(frontend): surface upload API error details (#1113)
Preserve backend upload/list/delete error details in the frontend API layer so users see the actual server failure instead of a generic message. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
This commit is contained in:
@@ -29,6 +29,16 @@ export interface ListFilesResponse {
|
|||||||
count: number;
|
count: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function readErrorDetail(
|
||||||
|
response: Response,
|
||||||
|
fallback: string,
|
||||||
|
): Promise<string> {
|
||||||
|
const error = await response
|
||||||
|
.json()
|
||||||
|
.catch(() => ({ detail: fallback }));
|
||||||
|
return error.detail ?? fallback;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload files to a thread
|
* Upload files to a thread
|
||||||
*/
|
*/
|
||||||
@@ -51,10 +61,7 @@ export async function uploadFiles(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const error = await response
|
throw new Error(await readErrorDetail(response, "Upload failed"));
|
||||||
.json()
|
|
||||||
.catch(() => ({ detail: "Upload failed" }));
|
|
||||||
throw new Error(error.detail ?? "Upload failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.json();
|
return response.json();
|
||||||
@@ -71,7 +78,9 @@ export async function listUploadedFiles(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Failed to list uploaded files");
|
throw new Error(
|
||||||
|
await readErrorDetail(response, "Failed to list uploaded files"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.json();
|
return response.json();
|
||||||
@@ -92,7 +101,7 @@ export async function deleteUploadedFile(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Failed to delete file");
|
throw new Error(await readErrorDetail(response, "Failed to delete file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.json();
|
return response.json();
|
||||||
|
|||||||
Reference in New Issue
Block a user