Skip to content

Commit aca473f

Browse files
William Wedlermarcandre
authored andcommitted
reject when load has an "error" status
This allows for a callback to be registered with the promise to handle errors like a 404. Without calling reject, the promise is always in a pending state.
1 parent c4ed123 commit aca473f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/featherlight.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,11 @@
282282

283283
/* Set content and show */
284284
return $.when($content)
285-
.always(function($content){
286-
self.setContent($content);
287-
self.afterContent(event);
285+
.always(function($openendContent){
286+
if($openendContent) {
287+
self.setContent($openendContent);
288+
self.afterContent(event);
289+
}
288290
})
289291
.then(self.$instance.promise())
290292
/* Call afterOpen after fadeIn is done */
@@ -395,7 +397,7 @@
395397
if ( status !== "error" ) {
396398
deferred.resolve($container.contents());
397399
}
398-
deferred.fail();
400+
deferred.reject();
399401
});
400402
return deferred.promise();
401403
}

test/featherlight_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,18 @@ var stubAjaxLoad = function(content) {
282282
});
283283
});
284284

285+
it('can recover from an ajax load error, like a 404', function(done) {
286+
var modal = new $.featherlight({ajax: 'bad-url-not-found.html'});
287+
var p = modal.open();
288+
var callbackCalled = false;
289+
p.fail(function() {
290+
callbackCalled = true;
291+
})
292+
patiently(done, function() {
293+
expect(callbackCalled).to.be.true;
294+
});
295+
});
296+
285297
it('ajax content can be text only', function(done) {
286298
stubAjaxLoad('Hello <b>world</b>');
287299
$.featherlight({ajax: 'stubbed'});

0 commit comments

Comments
 (0)