web: handle errors when resolving upload urls

This commit is contained in:
Abdullah Atta
2024-06-07 10:30:36 +05:00
parent ef93ecc481
commit a6af92c330

View File

@@ -296,12 +296,15 @@ async function singlePartUploadFile(
console.log("Streaming file upload!");
const { url, headers, signal } = requestOptions;
const uploadUrl = await fetch(url, {
const uploadUrl: string | { error?: string } = await fetch(url, {
method: "PUT",
headers,
signal
}).then((res) => (res.ok ? res.text() : null));
if (!uploadUrl) throw new Error("Unable to resolve attachment upload url.");
}).then((res) => (res.ok ? res.text() : res.json()));
if (typeof uploadUrl !== "string")
throw new Error(
uploadUrl.error || "Unable to resolve attachment upload url."
);
const response = await axios.request({
url: uploadUrl,
@@ -354,6 +357,9 @@ async function multiPartUploadFile(
throw new WrappedError("Could not initiate multi-part upload.", e);
});
if (initiateMultiPartUpload.data.error)
throw new Error(initiateMultiPartUpload.data.error);
uploadId = initiateMultiPartUpload.data.uploadId;
const { parts } = initiateMultiPartUpload.data;