From 5a8481416f85d4828cef35bd45d779160258079d Mon Sep 17 00:00:00 2001 From: Ryanba <92616678+Gujiassh@users.noreply.github.com> Date: Fri, 13 Mar 2026 21:55:33 +0800 Subject: [PATCH] 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 Co-authored-by: Willem Jiang --- frontend/src/core/uploads/api.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/frontend/src/core/uploads/api.ts b/frontend/src/core/uploads/api.ts index 3572551..0d83b6f 100644 --- a/frontend/src/core/uploads/api.ts +++ b/frontend/src/core/uploads/api.ts @@ -29,6 +29,16 @@ export interface ListFilesResponse { count: number; } +async function readErrorDetail( + response: Response, + fallback: string, +): Promise { + const error = await response + .json() + .catch(() => ({ detail: fallback })); + return error.detail ?? fallback; +} + /** * Upload files to a thread */ @@ -51,10 +61,7 @@ export async function uploadFiles( ); if (!response.ok) { - const error = await response - .json() - .catch(() => ({ detail: "Upload failed" })); - throw new Error(error.detail ?? "Upload failed"); + throw new Error(await readErrorDetail(response, "Upload failed")); } return response.json(); @@ -71,7 +78,9 @@ export async function listUploadedFiles( ); 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(); @@ -92,7 +101,7 @@ export async function deleteUploadedFile( ); if (!response.ok) { - throw new Error("Failed to delete file"); + throw new Error(await readErrorDetail(response, "Failed to delete file")); } return response.json();