the $.i18n().load method returns a jquery promise.
|
function jsonMessageLoader( url ) { |
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();
}
the
$.i18n().loadmethod returns a jquery promise.jquery.i18n/src/jquery.i18n.messagestore.js
Line 23 in 6afc05a
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.