prefetch-image
prefetch-image copied to clipboard
Introduce error handling on loadImage
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
能有重现的例子么?
是偶尔出现的,目前100条数据,也就出现了5次左右,返回的code是正常的,就是name不对; 代码如下: location.changeLocation(selectSsq[0], selectSsq[1], selectSsq[2]); let selectLocation = location.getCurrentAddress(); formData.provinceCode = selectLocation.province.code; formData.provinceName = selectLocation.province.name; formData.cityCode = selectLocation.city.code; formData.cityName = selectLocation.city.name; formData.areaCode = selectLocation.district.code; formData.areaName = selectLocation.district.name;
出现错误的是哪些城市/区错了?直接调方法100次,还是通过页面联动点击那种?
通过页面联动,在提交数据时,获取到选择的省市区code,再执行我发的那段代码,获取省市区名字,目前遇到出现错误的有: 陕西省/新城区/新城区、江苏省/海陵区/海陵区、江苏省/鼓楼区/鼓楼区、安徽省/镜湖区/镜湖区、贵州省/南明区/南明区、广东省/香洲区/香洲区、北京市/东城区/东城区
以上城市/区是偶尔出现,不是每次都出现
试了几次重现不了 😅