From 6a2b9070b9ce2d426e3fa44c37b40430d23e1f72 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 16 May 2023 15:28:24 +0100 Subject: [PATCH] feat: check if the fetch is successful before uploading the image --- src/editor/Cloud.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/editor/Cloud.tsx b/src/editor/Cloud.tsx index 20e5e2e0..f79f2e2a 100644 --- a/src/editor/Cloud.tsx +++ b/src/editor/Cloud.tsx @@ -16,7 +16,11 @@ const uploadResources = async (text: string) => { const url = match[3] const toastId = toast.loading(`Uploading ${altText || url}`) try { - const blob = await fetch(url).then((response) => response.blob()) + const response = await fetch(url) + if (!response.ok) { + throw new Error(response.statusText) + } + const blob = await response.blob() const key = (await UploadFile(blob)).key toast.success(`Uploaded ${altText || url}!`, { id: toastId,