Is there a way to ensure $q.all is triggered even if the promises return errors?
I'm working on a project where I need to make multiple $http.post requests, sending user-inputted values from text fields. The backend (Django REST framework) has a value checker that returns a 400 status if the posted value doesn't match the expected format. This causes $q.all not to trigger, leading to various errors in my application.
//Code snippet for handling $http post requests
for(var i = 0; i < num_requests; i++){
var writeRes = $http({
method: 'POST',
url: '/' + api_prefix + '/values/',
data: out_data,
headers: { 'Content-Type': 'application/json','X-CSRFToken': $scope.valueForm.csrf_token,'Accept': 'application/json;data=verbose' }
});
saved.push(writeRes);
writeRes.success(function(data, status, headers, config){
$scope.scope.param_values.push(data.id);
});
error(function(status){
//Handle error here
});
}
$q.all(saved).then(function() {
//Perform other tasks once all requests are completed
}
The correct values are being posted, but if an error occurs, the processing after $q.all doesn't get executed, causing issues upon page refresh.
Is there a way to make sure that $q.all runs regardless of any errors?
I apologize if my questions are unclear, as I am relatively new to frontend development and struggling with this project.