feat: check if the fetch is successful before uploading the image

This commit is contained in:
DIYgod
2023-05-16 15:28:24 +01:00
parent 095257ad5a
commit 6a2b9070b9
+5 -1
View File
@@ -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,