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.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 77cfe984-2c65-4152-bb7a-0df28274fe66
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: f8e5e0c4-e226-4048-ba47-93918e723879
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/c3c252e4-c83d-40ca-9fff-99a3ea60701e/77cfe984-2c65-4152-bb7a-0df28274fe66/qxUqlQr
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
riyadhafraa
2026-05-19 11:49:08 +00:00
parent a9b4fd86ff
commit 1416a9352b
+9 -1
View File
@@ -179,7 +179,15 @@ export function useUpload(options: UseUploadOptions = {}) {
}); });
if (!response.ok) { 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(); const data = await response.json();