diff --git a/public/scripts/network.js b/public/scripts/network.js index baaaced..85830d0 100644 --- a/public/scripts/network.js +++ b/public/scripts/network.js @@ -204,7 +204,7 @@ class Peer { } getResizedImageDataUrl(file, width = undefined, height = undefined, quality = 0.7) { - return new Promise((resolve) => { + return new Promise((resolve, reject) => { let image = new Image(); image.src = URL.createObjectURL(file); image.onload = _ => { @@ -233,9 +233,10 @@ class Peer { let dataUrl = canvas.toDataURL("image/jpeg", quality); resolve(dataUrl); } + image.onerror = _ => reject(`Could not create an image thumbnail from type ${file.type}`); }).then(dataUrl => { return dataUrl; - }) + }).catch(e => console.error(e)); } async requestFileTransfer(files) { diff --git a/public/scripts/ui.js b/public/scripts/ui.js index 4f73e5d..af5d3ae 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -516,10 +516,12 @@ class ReceiveFileDialog extends ReceiveDialog { element.src = URL.createObjectURL(file); element.controls = true; element.classList.add('element-preview'); - this.$previewBox.appendChild(element) - element.onload = _ => resolve(true); + element.onload = _ => { + this.$previewBox.appendChild(element); + resolve(true) + }; element.addEventListener('loadeddata', _ => resolve(true)); - element.onerror = _ => reject(`${mime} preview could not be loaded`); + element.onerror = _ => reject(`${mime} preview could not be loaded from type ${file.type}`); } }); }