This weekend I tried to understand the same thing. Based on what Luke said, I took a closer look at the ember-data data source for the last commit (December 11th).
TL; DR; to handle ember-data / create errors, just define becameError() and becameInvalid(errors) on your DS.Model instance. The cascade caused by the AJAX RESTadapter error callback will eventually call these functions that you define.
Example:
App.Post = DS.Model.extend title: DS.attr "string" body: DS.attr "string" becameError: -> # handle error case here alert 'there was an error!' becameInvalid: (errors) -> # record was invalid alert "Record was invalid because: #{errors}"
Here's a full walk on the source:
In the REST adapter, the AJAX callback function is provided here :
this.ajax(this.buildURL(root, id), "PUT", { data: data, context: this, success: function(json) { Ember.run(this, function(){ this.didUpdateRecord(store, type, record, json); }); }, error: function(xhr) { this.didError(store, type, record, xhr); } });
didError is defined here , and it in turn raises a storeWasInvalid or recordWasError entry depending on the response:
didError: function(store, type, record, xhr) { if (xhr.status === 422) { var data = JSON.parse(xhr.responseText); store.recordWasInvalid(record, data['errors']); } else { store.recordWasError(record); } },
In turn, store.recordWasInvalid and store.recordWasError (defined here ) call write handlers (DS.Model). In the invalid case, it passes error messages from the adapter as an argument.
recordWasInvalid: function(record, errors) { record.adapterDidInvalidate(errors); }, recordWasError: function(record) { record.adapterDidError(); },
DS.Model.adapterDidInvalidate and adapterDidError (defined here ) are just send('becameInvalid', errors) or send('becameError') , which ultimately leads us to the handlers here :
didLoad: Ember.K, didUpdate: Ember.K, didCreate: Ember.K, didDelete: Ember.K, becameInvalid: Ember.K, becameError: Ember.K,
(Ember.K is just a dummy function to return this . See here )
So, the conclusion is that you just need to define functions for becameInvalid and becameError for your model to handle these cases.
Hope this helps someone else; documents, of course, do not reflect this right now.