Improve error reporting for failed upload requests

Add detailed error messages, including HTTP status and server-provided details, to upload failures in lib/object-storage-web/src/use-upload.ts.
This commit is contained in:
Riyadh
2026-05-19 11:49:08 +00:00
parent a5df812f48
commit 356ab2c7c8
+9 -1
View File
@@ -179,7 +179,15 @@ export function useUpload(options: UseUploadOptions = {}) {
});
if (!response.ok) {
throw new Error("Failed to get upload URL");
const errorData = await response.json().catch(() => ({}));
const serverMsg =
(typeof errorData?.error === "string" && errorData.error) ||
(typeof errorData?.message === "string" && errorData.message) ||
"";
const detail = serverMsg
? `${serverMsg} (HTTP ${response.status})`
: `HTTP ${response.status} ${response.statusText || ""}`.trim();
throw new Error(`Failed to get upload URL: ${detail}`);
}
const data = await response.json();