Reputation: 684
I have a RESTful service that, when I try to save a new record does a unique email check. When it fails, I return a 400 error code along with a JSON message with an "errors" value in it.
Unfortunately, my error callback on my save doesn't seem to be firing. Any suggestions?
var nRecord = new RecordModel(values);
nRecord.save({
wait: true,
error: function(model,response){
console.log('error2');
obj.errorHandler(model,response);
},
success: function() {
console.log('success2');
obj.alert('Information saved!','Record Created!','success');
// if there were no errors, clear the list
$('#record-form :input').val('');
}
});
"Error2" is never displayed in the console. Thoughts?
Upvotes: 2
Views: 1328
Reputation: 226
I had this issue and the problem was i was overwriting the sync in the model. This meant the options was not getting passed in.
completeCustomer.save(null, {
wait: true,
error: function(model,response){
console.log('error2');
//obj.errorHandler(model,response);
_.bind(this.handleError, this);
},
success: function() {
console.log('success2');
//_.bind(this.handleSuccess, this);
}
});
Upvotes: 1
Reputation: 1198
You seem to be passing your error handler and other options as model attributes and saved into the model instead. Trying passing null as a first parameter to the save function. Hopefully this will make it work :)
nRecord.save(null,{
wait: true,
error: function(model,response){
console.log('error2');
obj.errorHandler(model,response);
},
success: function() {
console.log('success2');
obj.alert('Information saved!','Record Created!','success');
// if there were no errors, clear the list
$('#record-form :input').val('');
}
});
Upvotes: 8