From 8e25a70111a1d3bb0d65729df39d9876d7f9ea56 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Wed, 6 May 2020 19:58:52 +0200 Subject: [PATCH] fix: uncaught exceptions, still need to reject promise Revert "fix: uncaught exceptions, still need to reject promise" This reverts commit 5faa5f636616a9f5af891902640ee8c0b5ad5cc9. fix: catch uncaught error in scale transformation fix: resolveWrapper never rejected errors Revert "fix: catch uncaught error in scale transformation" This reverts commit 8e9386555621b1e55d32e6a88f3be4e1fc7ae81a. fix: catch any transformation error fix: prettier --- js/load-image.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/js/load-image.js b/js/load-image.js index 8f31a96..49ab8a9 100644 --- a/js/load-image.js +++ b/js/load-image.js @@ -45,6 +45,9 @@ // Not using Promises if (resolve) resolve(img, data) return + } else if (img instanceof Error) { + reject(img) + return } data = data || {} // eslint-disable-line no-param-reassign data.image = img @@ -159,10 +162,15 @@ loadImage.onload = function (img, event, file, url, callback, options) { revokeHelper(url, options) - loadImage.transform(img, options, callback, file, { - originalWidth: img.naturalWidth || img.width, - originalHeight: img.naturalHeight || img.height - }) + + try { + loadImage.transform(img, options, callback, file, { + originalWidth: img.naturalWidth || img.width, + originalHeight: img.naturalHeight || img.height + }) + } catch (error) { + callback(error) + } } loadImage.createObjectURL = function (file) {