AmpersandJS / ampersand-model

Observable objects, for managing state in applications.
MIT License
84 stars 31 forks source link

wrapError model param is descoped by options.error model param #38

Closed engenb closed 9 years ago

engenb commented 9 years ago

the code in question:

// Wrap an optional error callback with a fallback error event.
var wrapError = function (model, options) {
    var error = options.error;
    options.error = function (model, resp, options) {
        if (error) error(model, resp, options);
        model.trigger('error', model, resp, options);
    };
};

model.trigger(...) is expecting the model from wrapError arguments, but instead is model from options.error. We can see from ampersand-sync that the first argument is the response and not the model in this scenario:

    // Make the request. The callback executes functions that are compatible
    // With jQuery.ajax's syntax.
    var request = options.xhr = xhr(ajaxSettings, function (err, resp, body) {
        if (err && options.error) return options.error(resp, 'error', err.message);
yocontra commented 9 years ago

Also having this issue, causing errors every time a request has an error

lukekarrys commented 9 years ago

CLosed by #39