I have two forms with data that needs to be saved using two separate post APIs. I am using Promise.all() to save all the data from these two forms at once and its working as it should. The code is as follows:
saveAll() {
Promise.all([
this.$axios.post('v1/dummy-api/one',
this.saveFormOne()
),
this.$axios.post('v1/dummy-api/two',
this.saveFormTwo()
)
])
.then(() => {
this.success = 'Added Successfully.';
})
.catch(error => {
this.error = 'Error.';
})
},
The issue am trying to solve is I need to check if any of those two request fails and if it does then prevent/cancel the saving of the other one (which succeed) until all of them succeed. I've tried try/catch with no luck.
Any help will greatly appreciated!