title: Handling errors in Promise.all
body: <p>I have an array of Promises that I'm resolving with <code>Promise.all(arrayOfPromises);</code></p>
  
  <p>I go on to continue the promise chain. Looks something like this</p>
  
  <pre><code>existingPromiseChain = existingPromiseChain.then(function() {
    var arrayOfPromises = state.routes.map(function(route){
      return route.handler.promiseHandler();
    });
    return Promise.all(arrayOfPromises)
  });
  
  existingPromiseChain = existingPromiseChain.then(function(arrayResolved) {
    // do stuff with my array of resolved promises, eventually ending with a res.send();
  });
  </code></pre>
  
  <p>I want to add a catch statement to handle an individual promise in case it errors, but when I try, <code>Promise.all</code> returns the first error it finds (disregards the rest), and then I can't get the data from the rest of the promises in the array (that didn't error).</p>
  
  <p>I've tried doing something like ..</p>
  
  <pre><code>existingPromiseChain = existingPromiseChain.then(function() {
        var arrayOfPromises = state.routes.map(function(route){
          return route.handler.promiseHandler()
            .then(function(data) {
               return data;
            })
            .catch(function(err) {
               return err
            });
        });
        return Promise.all(arrayOfPromises)
      });
  
  existingPromiseChain = existingPromiseChain.then(function(arrayResolved) {
        // do stuff with my array of resolved promises, eventually ending with a res.send();
  });
  </code></pre>
  
  <p>But that doesn't resolve.</p>
  
  <p>Thanks!</p>
  
  <p>--</p>
  
  <p>Edit:</p>
  
  <p>What the answers below said were completely true, the code was breaking due to other reasons. In case anyone is interested, this is the solution I ended up with ...</p>
  
  <p>Node Express Server Chain</p>
  
  <pre><code>serverSidePromiseChain
      .then(function(AppRouter) {
          var arrayOfPromises = state.routes.map(function(route) {
              return route.async();
          });
          Promise.all(arrayOfPromises)
              .catch(function(err) {
                  // log that I have an error, return the entire array;
                  console.log('A promise failed to resolve', err);
                  return arrayOfPromises;
              })
              .then(function(arrayOfPromises) {
                  // full array of resolved promises;
              })
      };
  </code></pre>
  
  <hr>
  
  <p>API Call (route.async call)</p>
  
  <pre><code>return async()
      .then(function(result) {
          // dispatch a success
          return result;
      })
      .catch(function(err) {
          // dispatch a failure and throw error
          throw err;
      });
  </code></pre>
  
  <p>Putting the <code>.catch</code> for <code>Promise.all</code> before the <code>.then</code> seems to have served the purpose of catching any errors from the original promises, but then returning the entire array to the next <code>.then</code></p>
  
  <p>Thanks! </p>