Is there any way to get the result object on Promise.all.catch
?
I'd like to do two inserts in a database, one in a MySQL database and one in a MongoDB database. If one of them fails I'd like to delete the other one.
Here is some pseudo code
const mysqlPromise = mysql.query('insert to table')
const mongoPromise = mongodb.insert('insert to collaction')
Promise.all([mysqlPromise,mongoPromise])
.then(result =>{
})
//i know it doesnt work that way but this is what i need to achive
.catch((err,result) =>{
if(err[0] && err[1]){
//do nothing
return
}
if(err[0]){
mongodb.delete({_id:result[1].insertId})
}
else{
mysql.query('delete from table where id = 'result[0].lastInsertId)
}
})