Skip to content

Commit

Permalink
Merge pull request #3048 from braddunbar/error
Browse files Browse the repository at this point in the history
Pass along `textStatus` and `errorThrown`.
  • Loading branch information
jashkenas committed Mar 15, 2014
2 parents e0b84c4 + cbaa8d1 commit 2543be2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,14 @@
};
}

// Pass along `textStatus` and `errorThrown` from jQuery.
var error = options.error;
options.error = function(xhr, textStatus, errorThrown) {
options.textStatus = textStatus;
options.errorThrown = errorThrown;
if (error) error.apply(this, arguments);
};

// Make the request, allowing the user to override any Ajax options.
var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
model.trigger('request', model, xhr, options);
Expand Down
11 changes: 11 additions & 0 deletions test/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,15 @@
strictEqual(this.ajaxSettings.beforeSend(xhr), false);
});

test('#2928 - Pass along `textStatus` and `errorThrown`.', 2, function() {
var model = new Backbone.Model;
model.url = '/test';
model.on('error', function(model, xhr, options) {
strictEqual(options.textStatus, 'textStatus');
strictEqual(options.errorThrown, 'errorThrown');
});
model.fetch();
this.ajaxSettings.error({}, 'textStatus', 'errorThrown');
});

})();

0 comments on commit 2543be2

Please sign in to comment.