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:
Ryanba
2026-03-13 21:55:33 +08:00
committed by GitHub
parent a79d414695
commit 5a8481416f

View File

@@ -29,6 +29,16 @@ export interface ListFilesResponse {
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
*/
@@ -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();