title: jQuery .when().then() not working as expected
body: <p>I have an object which acts as a client side API Client which exposes several functions which all return jQuery ajax() objects. Some of those ajax calls have <code>.done()</code> and <code>.fail()</code> calls chained directly onto them because they are actions which need to be taken every time the API responses come back before the rest of the js code is allowed to deal with the response. Pretty standard stuff.</p>
  
  <p>I need to kick off a variable number of API requests, wait for all to fail or succeed, and then continue processing. For the examples I will create, I will simplify this down to just two ajax calls.</p>
  
  <p>So I create an array to hold the returned ajax objects, and then use <code>$.when().apply(null, deferreds).then(function(){//do something after both ajax requests complete})</code>. When the calls complete successfully, everything works great. When calls fail (such as if the ajax call 404s), things are not so great.</p>
  
  <p>The problem is that <code>.then()</code> doesn't seem to detect the fails, <a href="https://api.jquery.com/deferred.then/" rel="nofollow noreferrer">even though I thought <code>then()</code> was supposed to be fired regardless of success or failure of the underlying promise(s)</a>. </p>
  
  <p>I can switch to <code>.always()</code>, which seems to work better (in that it detects the failures and still triggers the callback) but it seems to fire before some of the <code>.fail()</code> callbacks that are registered directly on the ajax calls, which doesn't make sense to me since I thought the callbacks for an ajax call were called in the order they were registered.</p>
  
  <p>I'm sure I'm just missing something about the behavior of the <code>ajax()</code> <code>when()</code> <code>then()</code> combo.</p>
  
  <p>Fiddle showing successful calls using <code>.then()</code>: <a href="https://jsfiddle.net/kwrLyw6q/5/" rel="nofollow noreferrer">https://jsfiddle.net/kwrLyw6q/5/</a></p>
  
  <p>Fiddle using <code>.then()</code> with failed ajax calls (not working, would love to know why. Seems like this is the "right" way to do it, but I can't figure out where I'm going wrong): <a href="https://jsfiddle.net/kwrLyw6q/2/" rel="nofollow noreferrer">https://jsfiddle.net/kwrLyw6q/2/</a></p>
  
  <p>Fiddle using <code>.always()</code> (working, but notice the out-of-order callback order. At least, out of order compared to the order I want them!): <a href="https://jsfiddle.net/kwrLyw6q/7/" rel="nofollow noreferrer">https://jsfiddle.net/kwrLyw6q/7/</a></p>