title: Catch / Handle 502 Bad Gateway Error
body: <p>I have to update a large collection so I am calling in a loop an web api. I use <code>jQuery.ajax()</code>
  Something like this:</p>
  
  <pre><code>$.ajax({
     type: 'GET',
      url: 'http://www.somesite.com/API/API.php',
      jsonpCallback: 'API_SC4',
      contentType: "application/json",
      dataType: 'jsonp',
      data:'action=update&amp;page='+collection[currentIndex].name+'&amp;callback=API_SC4',
      async:false,
      success: function(data) {
  
          //use data for update of collection[currentIndex]
  
          UpdateNext(currentIndex+1);
      },
      error: function(e) {
         //interpret error
         UpdateNext(currentIndex+1);
      }
  });
  </code></pre>
  
  <p>The problem is the collection is quite large and sometimes I get a 502 Bad Gateway error and the ajax error handler is not called. </p>
  
  <p>I even tried <code>$( document ).ajaxError()</code> but i'm doing a cross-domain jsonp call , and it seems <code>.ajaxError()</code> does not get called in that situation.</p>
  
  <p>Is there any way to handle that error? Something at window level?<br>
  I can see the error in the Chrome development console , and I was thinking there might be a way.</p>
  
  <p>Thanks</p>