FIX: Transaction was aborting before all promises have either resolved or rejected (#5878)

This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2019-07-31 18:34:49 -07:00
committed by GitHub
parent baa5daefa4
commit 14a8d333a3
5 changed files with 360 additions and 43 deletions

View File

@@ -107,33 +107,26 @@ function handleBatch(router, req) {
return { success: response.response };
},
error => {
if (req.body.transaction === true) {
return Promise.reject(error);
}
return { error: { code: error.code, error: error.message } };
}
);
});
return Promise.all(promises)
.catch(error => {
if (req.body.transaction === true) {
return Promise.all(promises).then(results => {
if (req.body.transaction === true) {
if (results.find(result => typeof result.error === 'object')) {
return req.config.database.abortTransactionalSession().then(() => {
throw error;
return Promise.reject({ response: results });
});
} else {
throw error;
}
})
.then(results => {
if (req.body.transaction === true) {
return req.config.database.commitTransactionalSession().then(() => {
return { response: results };
});
} else {
return { response: results };
}
});
} else {
return { response: results };
}
});
});
}