Skip to content

the load function does not fail the promise correctly #255

@shankari

Description

@shankari

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();
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions