Created
September 5, 2018 10:37
-
-
Save xmalinov/26b020ca7b3a3e5022477b91e96d7547 to your computer and use it in GitHub Desktop.
DMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Строки урлов с токенами | |
var requests = [ | |
{url: urlTargets1}, | |
{url: urlTargets2}, | |
{url: urlTargets3}, | |
{url: urlTargets4}, | |
{url: urlTargets5} | |
] | |
// Собираем массив из запросов | |
var promises = [] | |
for (var i = 0; i < requests.length; i++) { | |
promises.push(axios.get(requests[i].url, { | |
withCredentials: true | |
})) | |
} | |
// Проверяем все промисы независимо от кетчовой ошибки | |
var promisesResolved = promises.map(promise => promise.catch(error => ({ error }))) | |
function checkFailed (then) { | |
return function (responses) { | |
var someFailed = responses.some(response => response.error) | |
if (someFailed) { | |
throw responses | |
} | |
return then(responses) | |
} | |
} | |
// Запускаем все промисы | |
axios.all(promisesResolved) | |
.then(checkFailed(([someUrl, anotherUrl]) => { | |
console.log('Full success', someUrl, anotherUrl) | |
})) | |
.catch((data) => { | |
console.log('Recieved data', data) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment