documentcloud/backbone — Issue #690: Error object is lost in the wrapped error callback after successful update and failed validation
Author: bubenshchykov
Created: 2011-10-26 00:00:56+00:00
State: open

Hi guys,

I read about error handling issues and suggestions, but seems like I've got another problem

Scenario:
Model updates -> Success callback -> Set updated attributes -> Validation fails (Ok, it should be) -> Error callback has model instead of error object (so not able to give user a feedback)

The wrapError function returns a wrapped callback what has One param called resp
function(resp) {
if (onError) {
onError(model, resp, options);
} else {
model.trigger('error', model, resp, options);
}
}
and _performValidation calles it with three params, first one is model (this)

_performValidation : function(attrs, options) {
var error = this.validate(attrs);
if (error) {
if (options.error) {
options.error(this, error, options);
..

so wrapped error callback takes this first given param - a model instead of error object

Note, that it happens only when called from validation after update.
- If it's called from Ajax Error (like Update fails) - it also gives all three params, but a proper first param (resp) is read as expected, then I have a check and convert this responseText to my error object (I handle both client and server side validation with one callback and check inside) - works fine.
- If validation fails before Update - error callback is not wrapped, and everyth is fine too

Please, assist