mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
web: handle errors when resolving upload urls
This commit is contained in:
@@ -296,12 +296,15 @@ async function singlePartUploadFile(
|
|||||||
console.log("Streaming file upload!");
|
console.log("Streaming file upload!");
|
||||||
const { url, headers, signal } = requestOptions;
|
const { url, headers, signal } = requestOptions;
|
||||||
|
|
||||||
const uploadUrl = await fetch(url, {
|
const uploadUrl: string | { error?: string } = await fetch(url, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers,
|
headers,
|
||||||
signal
|
signal
|
||||||
}).then((res) => (res.ok ? res.text() : null));
|
}).then((res) => (res.ok ? res.text() : res.json()));
|
||||||
if (!uploadUrl) throw new Error("Unable to resolve attachment upload url.");
|
if (typeof uploadUrl !== "string")
|
||||||
|
throw new Error(
|
||||||
|
uploadUrl.error || "Unable to resolve attachment upload url."
|
||||||
|
);
|
||||||
|
|
||||||
const response = await axios.request({
|
const response = await axios.request({
|
||||||
url: uploadUrl,
|
url: uploadUrl,
|
||||||
@@ -354,6 +357,9 @@ async function multiPartUploadFile(
|
|||||||
throw new WrappedError("Could not initiate multi-part upload.", e);
|
throw new WrappedError("Could not initiate multi-part upload.", e);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (initiateMultiPartUpload.data.error)
|
||||||
|
throw new Error(initiateMultiPartUpload.data.error);
|
||||||
|
|
||||||
uploadId = initiateMultiPartUpload.data.uploadId;
|
uploadId = initiateMultiPartUpload.data.uploadId;
|
||||||
const { parts } = initiateMultiPartUpload.data;
|
const { parts } = initiateMultiPartUpload.data;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user