If you want to capture the failure of a promise and turn it into success, you can use failFilter then to return the allowed promises, for example like this:
deferredCall.then(function(answer) {
Doing this ensures that the chain can continue to fail without interruption.
So, for your example, you can do this:
$.when([ a.ajax(), b.ajax().then(function(answer) { return answer; }, function() { return $.Deferred().resolve({}).promise(); }), c.ajax() ]).then(function(results) {
Example 2. In my applications, I sometimes use then to obtain relational data for a specific object and allow the possibility of 404 to indicate that there is no such relation exists:
getEntity(id).then(function(entity) { return getAssociation(id).then(function(association) { entity.association = association; return entity; }, function() { entity.association = null; return $.Deferred().resolve(entity).promise(); }); }).done(function(entity) {
Note. Older answers suggest using the pipe method. This method is deprecated from jQuery 1.8.
source share