I have two functions which return calls to AngularJS' $http.post. The two functions are savePart1() & savePart2()
savePart1 = (): IPromise<any> => {
return $http.post(....)
}
savePart2 = (): IPromise<any> => {
return $http.post(....)
}
I am trying to not callPart2() if savePart1() fails. I did something like this:
this.savePart1().then((response1) => {
if (response1.status !== 200)
// don't call savePart2()
this.savePart2().then((response2) => {
if(response1.status === 200)
//display success message when both calls succeed
}):
}), (error) => {
//handle error;
}).finally();
My question is how to cancel from calling savePart2() if the response from savePart2() did not return status of 200 (not necessarily an error). IPromise doesn't seem to have a reject method. Do I just return from the first promise?
Also my goal is to display a success message when both calls succeed. Is my syntax the best way to do this. I would like to add an error handler when any call fails.