From 446cd5a58b22b6771a35696f4dfe4063f4998ebe Mon Sep 17 00:00:00 2001 From: catboxanon <122327233+catboxanon@users.noreply.github.com> Date: Sat, 16 Mar 2024 20:19:12 -0400 Subject: [PATCH] dragdrop: add error handling for URLs --- javascript/dragdrop.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/javascript/dragdrop.js b/javascript/dragdrop.js index 86591aa24..0c0183564 100644 --- a/javascript/dragdrop.js +++ b/javascript/dragdrop.js @@ -93,11 +93,20 @@ window.document.addEventListener('drop', async e => { fileInput.files = files; fileInput.dispatchEvent(new Event('change')); } else if (url) { - const request = await fetch(url); - const data = new DataTransfer(); - data.items.add(new File([await request.blob()], 'image.png')); - fileInput.files = data.files; - fileInput.dispatchEvent(new Event('change')); + try { + const request = await fetch(url); + if (!request.ok) { + console.error('Error fetching URL:', url, request.status); + return; + } + const data = new DataTransfer(); + data.items.add(new File([await request.blob()], 'image.png')); + fileInput.files = data.files; + fileInput.dispatchEvent(new Event('change')); + } catch (error) { + console.error('Error fetching URL:', url, error); + return; + } } }