1

I have the following save:

 var saveResponse = rene.save({
            success: function(response, opts) {
                console.log('The Child was saved, response: '+response);
            },
            failure: function(response, opts) {
                console.log('The Child save was a failure response: '+response);
                console.log('The Child save was a failure opts: '+opts);
            }
        });

The server validates the data sent in, and in case of any errors it returns this:

{"validationErrors":{
    "phoneNumber":"Account with this email already exists",
    "birthDateString":"Use following format: yyyy-MM-dd. Example: 2012-11-22"}
}

But the save method has the following API which only returns:

http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Model-method-save

"...they will all be invoked with the Model and Operation as arguments.",

So my question is:

How can get the response (the JSON above) in return when it only provides me with the Model (I assume it only give me the original json I sent in the post body since I dont return the full model in return) ? Is it something I overlook, or shouldnt REST POST requests from a semantically point of view ever fail (here: validation errors)?

Thomas Vervik
  • 4,325
  • 9
  • 36
  • 64
  • http://stackoverflow.com/questions/1959947/whats-an-appropriate-http-status-code-to-return-by-a-rest-api-service-for-a-val Interesting link releated to my question, even thus they didnt reach a solution – Thomas Vervik Jul 26 '12 at 16:08

1 Answers1

1

I figured it out, you register the exception listener to the proxy like this:

var account = Ext.create('Sencha.model.user.Adult', {
....
}

var proxy = account.getProxy();
proxy.addListener({
    'exception': function(proxy, response, operation) {
        var obj = JSON.parse(response.responseText);
            adultClass.serverValidationErrors(obj);
        }
});
Thomas Vervik
  • 4,325
  • 9
  • 36
  • 64