I've already tried to get the fastest response but in chrome toolbar network i see all the responses but not the fastest. Also as i mentioned above I want to get all the successful responses and ignore rejected
const url = 'https://mate-academy.github.io/phone-catalogue-static/api/phones.json';
const detailsUrl = 'https://mate-academy.github.io/phone-catalogue-static/api/phones/';
const getPhones = () => {
return fetch(url)
.then(response => {
if (!response.ok) {
setTimeout(() => {
return Promise.reject(new Error('It was an accident'));
}, 5000);
}
return response.json();
});
};
const getFirstPhoneDetails = (arrId) => {
return Promise.race(arrId.map(id =>
fetch(`${detailsUrl}${id}.json`)));
};
getPhones()
.then(phones => {
const ids = phones.map(p => p.id);
return getFirstPhoneDetails(ids);
})
.catch(error => {
console.warn(error);
});