Skip to content

failure handling #7

@ahj

Description

@ahj

I've got the chaining part of my code working with your library - thanks because it really does simplify things!
But I still have a problem handling the failure case.
When an error occurs I want whatever string or struct that is passed to rejected to be available in the fail function.

       aSync1()
            .then(aSync2)
            .then(aSync3)
            .done(onSuccess)
            .fail(onFailure);

where aSync1, aSync2 and aSync3 are functions wrapping async requests.

I want onFailure to be called when ANY of the aSync functions fails - which it does.

My problem is getting any value being passed in the aSync function's call to reject to get propagated through to the onFailure function.

Looking at how resolve and reject (lines 127, 149) are implemented it looks like onDone and onFail are expected to return a value which then gets passed to the call to lastDfd's reject or resolve.

So then that makes me think the done, fail and always shouldn't be setting empty functions when passed a non function...

        if (typeof onFail === 'function')
            me.onFail = onFail;

instead of

        me.onDone = typeof onDone === 'function' ? onDone : function () {};

But then I'm still having to override the onFail, onDone method to actually return whatever's passed.

Is this application-specific behavior?
Is this something the developer is expected to override to get the intended behavior?

Right now I can make it all work 'as I expect it' with the following override...

Ext.define('Ext.ux.Deferred2', {
    override: 'Ext.ux.Deferred',

    onFail: function() {
        return arguments ? ((arguments.length === 1) ? arguments[0] : arguments) : undefined;
    },

    fail: function (onFail) {
        var me = this;

        if (typeof onFail === 'function') {
            me.onFail = onFail;
        }

        return me;
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions