I learn React JavaScript and have this Codesandbox where I don't understand why the error is not shown
Here in the watchProgress
the catch
is not fired but it's fired in the promise so I do something wrong
function watchProgress(promArray) {
let progress = 0;
promArray.forEach(p => {
p.then(result => {
progress += 1;
const percentCorrect = (progress / promArray.length) * 100;
const math = Math.floor(percentCorrect);
setProgressValue(math);
console.log(`name ${result.name}`);
}).catch(err => {
console.log(`err ${err}`);
});
});
}
- Select a file with the file picker
- Watch the log for
err
- The log show the
error
inside the promise but noterr
when I loop through all
Update
I try something like this but I get TypeError: p.then is not a function
Promise.all(promArray)
.then(arr => {
arr.forEach(p => {
p.then(result => {
progress += 1;
const percentCorrect = (progress / promArray.length) * 100;
const math = Math.floor(percentCorrect);
// console.log(`setProgressValue ${math}`);
// console.log(`count ${progress}`);
setProgressValue(math);
console.log(`name ${result.name}`);
}).catch(err => {
console.log(`err ${err}`);
});
});
})
.catch(err => {
console.log(`err ${err}`);
});