MOBILE-3039 core: Fix allPromises error detection

main
Dani Palou 2019-05-21 10:22:13 +02:00
parent 699813c640
commit 0f3c6099b3
1 changed files with 3 additions and 1 deletions

View File

@ -84,17 +84,19 @@ export class CoreUtilsProvider {
return new Promise((resolve, reject): void => {
const total = promises.length;
let count = 0,
hasFailed = false,
error;
promises.forEach((promise) => {
promise.catch((err) => {
hasFailed = true;
error = err;
}).finally(() => {
count++;
if (count === total) {
// All promises have finished, reject/resolve.
if (error) {
if (hasFailed) {
reject(error);
} else {
resolve();