Skip to content

Introduce error handling on loadImage #1

@desytech

Description

@desytech

Is there any reason to resolve the loadImage promise even if some image failed loading? Need some identification on my project if there is a failure on image loading.
I was not able to add a pull request. Put my changes in this issue.

@@ -126,7 +126,7 @@ function loadImages(images, imageLoadingInfo) {
  */
 function loadImage(src, container) {
   // console.log('--> start loading img: %s', src);
-  return new Promise((resolve) => {
+  return new Promise((resolve, reject) => {
     const img = new Image();
     img.onload = () => {
       // console.log(`src: ${src}`);
@@ -134,8 +134,7 @@ function loadImage(src, container) {
     };
     img.onerror = () => {
       console.error(`[prefetch-image]: "${src}" failed`);
-      //still resolve even if some image failed loading
-      resolve(src);
+      reject(src);
     };
     img.src = src;
     container.push(img);

Thanks

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions