Я создаю проект, используя angularjs. У меня проблема при вызове api с $ q.all.Here мой код:
$q.all({
getCustomerInfo: promocodeService.getCustomerInfo(),
assCustomerPromoCode: promocodeService.assCustomerPromoCode(),
getPromocodes:promocodeService.getPromocodes(),
getAllCurrencies:promocodeService.getAllCurrencies(),
}).then(function(resolved) {
// here not comes when one of the api is failed
$rootScope.customerInfo = resolved.getCustomerInfo;
$scope.assPromoCode = resolved.assCustomerPromoCode;
$scope.promoCodes = resolved.getPromocodes;
$scope.getAllCurrencies = resolved.getAllCurrencies;
});
Моя проблема в том, что когда один из api терпит неудачу, он не попадает в разрешенное состояние.
Это ожидаемое поведение. all
предназначено для выполнения, когда все они преуспевают.
Некоторые альтернативы, которые вы могли бы попробовать, в зависимости от ваших требований:
$q.all({
//...
}).then(function(resolved) {
//...
}).catch(function() {
//Do something?
}).finally(function() {
//Do something?
})
.catch(function(error) { //error handling })