我在Chrome和Mozilla浏览器中使用上述代码得到了正确的响应,但是对于IE浏览器,我收到了“ 504网络错误”。
我已经检查了没有Promise.all。 我注意到一件事,每当我们循环调用API时,都会遇到这种类型的网络错误。
/* Function to fetch Reference Api data */
async fetchRefAPIData(data, srnList, token) {
//Pushing all the request in promises const
const promises = data.models.map(async val => {
const splitString = val.srn.split('/');
if (splitString[splitString.length - 2] === 'questions-models') {
srnList.push(val.srn);
const srn = splitString[splitString.length - 1];
const referenceEndpoint = `${getReferenceEndpointwithoutSRN()}/${srn}`;
//Calling Reference API
const response = await axios({
method: 'GET',
url: referenceEndpoint,
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: token,
},
});
return {
srn,
title: response.data.title,
selectedCompleteSrn: val.srn,
modelType: val.type,
questions: response.data.questions,
selectedSurvey: srn,
srnState: val.state,
};
}
});
const results = [];
await Promise.all(promises).then(result => {
result.map(obj => {
if (obj !== undefined && obj !== false) {
results.push(obj);
}
});
});
//Return the final result
return results;
}