I have an aysnc function that fetches data and returns the value of Promise.all
i.e.
const fetchDownloadMenuData = async selectedItems => {
return Promise.all(
selectedItems.map(async item => {
try {
if (item.id === 'interviewGuide') {
const interviewGuide = await positionCandidatesService.getCandidate(
positionId,
candidateSelected.id
);
return interviewGuide.interviewGuide;
}
if (item.id !== 'overview' && item.id !== 'profile') {
const outcome = await outcomesService.get(candidateSelected.id, item.id);
return outcome;
}
return null;
} catch (err) {
appInsights.trackException({
error: new Error(`Error fetching candidate outcome: ${JSON.stringify(err)}`)
});
return null;
}
})
)};
I call this function like this:
try {
downloadData = await fetchDownloadMenuData(selectedItems);
} catch (err) {
appInsights.trackException({
error: new Error(`Could not fetch all PDF data: ${JSON.stringify(err)}`)
});
return;
}
But it never goes into the catch. Why is this? How do i get it to reject if all the promises don't resolve?
Thanks