title: Handling multiple promises within an array individually
body: <p>I have a function which makes web service calls to my server and returns an array of promises. </p>
  
  <p>However some of these calls might work while others might not. The way my function is currently set up, if one of them fails, it alerts that the entire thing failed. If I'm making 5 calls, 1 might fail. I need to log this correctly and I'm not sure how to do it. </p>
  
  <p>An ideal response/log would be: </p>
  
  <ol>
  <li>call 1 passed  </li>
  <li>call 2 passed</li>
  <li>call 3 passed</li>
  <li>call 4 failed - reason</li>
  <li>call 5 passed</li>
  </ol>
  
  <p>Right now the whole thing will return "The handle user operation failed" because call 4 failed. </p>
  
  <p>Function: </p>
  
  <pre><code>var manageGroup = function (add, group, users){
  
      var deffered = $q.defer();
      var arrPromises = [];
      var promiseIndex = arrPromises.length;
      var usersLength = users.length;
      var operation = add ? "AddUserToGroup" : "RemoveUserFromGroup";
      var actionText = add ? "Added: " : "Removed: "
      var actionText2 = add ? " to " : " from "
  
      //Apply operation on selected groups
      for (var i = 0; i &lt; usersLength; i++){
          arrPromises[i] = $().SPServices({
              operation: operation,
              groupName: group.name,
              userLoginName: users[i].domain
          });      
      }
  
      $q.all(arrPromises).then(
          function (){
              //when promises are finsihed
              for (var i = 0; i &lt; usersLength; i++){
                  console.log(actionText + users[i].name + actionText2  + group.name);
              };
              deffered.resolve();
          },
          //function incase of AJAX failure
          function (){
              alert('The handle user operation failed.');
          }
      ) 
      return deffered.promise;      
  }
  </code></pre>
  
  <p>I tried to handle the promises individually instead of using the $q.all but now I'm not getting anything in the log:</p>
  
  <p>I took this section out: </p>
  
  <pre><code>/*$q.all(arrPromises).then(
      function (){
          //when promises are finsihed
          for (var i = 0; i &lt; usersLength; i++){
              console.log(actionText + users[i].name + actionText2  + group.name);
          };
          deferred.resolve();
      },
      //function incase of AJAX failure
      function (){
          alert('The handle user operation failed.');
      }
  ) */
  </code></pre>
  
  <p>Introduced this instead:</p>
  
  <pre><code>for (var i = 0; i&lt;promiseIndex; i++){
      arrPromises[i].then(
          function (){
              console.log(actionText + user[i].name + actionText2 + group.name);
          }
      ),
      function (){
          alert('Failed to add/remove'+  user[i].name + ' to ' + group.name)
      }
  }
  
  $q.all(arrPromises).then(function (){
      deferred.resolve();
  }, function (){
      deferred.reject();
  })
  </code></pre>