Skip to content

Commit

Permalink
fix: add possibility to use own handling of onerror which will not en…
Browse files Browse the repository at this point in the history
…d up in the exception
  • Loading branch information
Michal Biroš committed Feb 8, 2024
1 parent 128b191 commit 8c8e816
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/embed-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ async function embedImageNode<T extends HTMLElement | SVGImageElement>(
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 {

Check warning on line 66 in src/embed-images.ts

View check run for this annotation

Codecov / codecov/patch

src/embed-images.ts#L66

Added line #L66 was not covered by tests
reject(new Error('Image failed to load'))
}
}

const image = clonedNode as HTMLImageElement
if (image.decode) {
Expand Down

0 comments on commit 8c8e816

Please sign in to comment.