I'm using Angular 1.6.3
I need to make 3 get requests and finally check if at least one gives success response. Right now I have written this code:
var result = new Array();
$http.get("link1",
{
"params": {
"email": user.email,
}
}).then(function (successResult) {
result[0] = false;
}, function (errorResult) {
result[0] = true;
});
$http.get("link2",
{
"params": {
"email": user.email,
}
}).then(function (successResult) {
result[1] = false;
}, function (errorResult) {
result[1] = true;
});
$http.get("link3",
{
"params": {
"email": user.email,
}
}).then(function (successResult) {
result[2] = false;
}, function (errorResult) {
result[2] = true;
});
if(result[0] || result[1] || result[2]){
error();
}
But sometimes one of GET requests returns -1 as Http status code when it should give 200. I know that all $http request are async and I think this is the main reason. What is the proper way to solve this issue?
[email protected]