Skip to content

Commit ef96f78

Browse files
authored
Merge pull request blueimp#111 from axa-ch/bugfix/drawImage-exceptions-not-handled
Uncaught exceptions aren't catched or rejected
2 parents b14e2df + 8e25a70 commit ef96f78

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

js/load-image.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
// Not using Promises
4646
if (resolve) resolve(img, data)
4747
return
48+
} else if (img instanceof Error) {
49+
reject(img)
50+
return
4851
}
4952
data = data || {} // eslint-disable-line no-param-reassign
5053
data.image = img
@@ -159,10 +162,15 @@
159162

160163
loadImage.onload = function (img, event, file, url, callback, options) {
161164
revokeHelper(url, options)
162-
loadImage.transform(img, options, callback, file, {
163-
originalWidth: img.naturalWidth || img.width,
164-
originalHeight: img.naturalHeight || img.height
165-
})
165+
166+
try {
167+
loadImage.transform(img, options, callback, file, {
168+
originalWidth: img.naturalWidth || img.width,
169+
originalHeight: img.naturalHeight || img.height
170+
})
171+
} catch (error) {
172+
callback(error)
173+
}
166174
}
167175

168176
loadImage.createObjectURL = function (file) {

0 commit comments

Comments
 (0)