From 8c8e81652d14369c4e4aa57756493debeb2c08e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Biro=C5=A1?= Date: Thu, 8 Feb 2024 10:06:01 +0100 Subject: [PATCH] fix: add possibility to use own handling of onerror which will not end up in the exception --- src/embed-images.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/embed-images.ts b/src/embed-images.ts index aa552e8f..e05186a5 100644 --- a/src/embed-images.ts +++ b/src/embed-images.ts @@ -55,7 +55,18 @@ async function embedImageNode( const dataURL = await resourceToDataURL(url, getMimeType(url), options) await new Promise((resolve, reject) => { clonedNode.onload = resolve - clonedNode.onerror = reject + clonedNode.onerror = async (...params) => { + if (clonedNode.onerror) { + try { + const result = await clonedNode.onerror(...params) + resolve(result) + } catch (error) { + reject(error) + } + } else { + reject(new Error('Image failed to load')) + } + } const image = clonedNode as HTMLImageElement if (image.decode) {