Skip to content

Commit ff8cd67

Browse files
committed
add another safeguard catch handler
1 parent cf710eb commit ff8cd67

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

web_src/js/utils.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,18 @@ export function convertImage(blob, mime) {
111111
const img = new Image();
112112
const canvas = document.createElement('canvas');
113113
img.addEventListener('load', () => {
114-
canvas.width = img.naturalWidth;
115-
canvas.height = img.naturalHeight;
116-
const context = canvas.getContext('2d');
117-
context.drawImage(img, 0, 0);
118-
canvas.toBlob((blob) => {
119-
if (!(blob instanceof Blob)) return reject(new Error('imageBlobToPng failed'));
120-
resolve(blob);
121-
}, mime);
114+
try {
115+
canvas.width = img.naturalWidth;
116+
canvas.height = img.naturalHeight;
117+
const context = canvas.getContext('2d');
118+
context.drawImage(img, 0, 0);
119+
canvas.toBlob((blob) => {
120+
if (!(blob instanceof Blob)) return reject(new Error('imageBlobToPng failed'));
121+
resolve(blob);
122+
}, mime);
123+
} catch (err) {
124+
reject(err);
125+
}
122126
});
123127
img.addEventListener('error', () => {
124128
reject(new Error('imageBlobToPng failed'));

0 commit comments

Comments
 (0)