jquery.i18n
jquery.i18n copied to clipboard
the `load` function does not fail the promise correctly
the $.i18n().load
method returns a jquery promise.
https://github.com/wikimedia/jquery.i18n/blob/6afc05ae64a2051d0a97b143ae90ca76f651874e/src/jquery.i18n.messagestore.js#L23
HOWEVER, if the load fails, the promise does not fail. The code explicitly traps the fail callback and converts it to a success callback. It appears that this is to handle 404 exceptions properly via fallbacks. But this also then does not catch other exceptions, such as invalid JSON.
It seems like it would be better to resolve only on the 404 exception, and reject on other exceptions. I am happy to submit a PR if that would be welcomed.
function jsonMessageLoader( url ) {
var deferred = $.Deferred();
$.getJSON( url )
.done( deferred.resolve )
.fail( function ( jqxhr, settings, exception ) {
$.i18n.log( 'Error in loading messages from ' + url + ' Exception: ' + exception );
// Ignore 404 exception, because we are handling fallabacks explicitly
deferred.resolve();
} );
return deferred.promise();
}