ember.js - Ember-data how best to handle non validation errors -


what best way handle 403 errors ember-data?

i want know best way handle non validation errors, example have bit of code might return http 403 if user not allowed perform action. example, have following code:

contact.set 'something', 'something'  transaction = @get('store').transaction()  transaction.add(contact)  contact.one 'becameinvalid', (result) =>   #display error message  contact.one 'becameerror', (result) =>   # code not here reason   transaction.rollback()   #display error message  transaction.commit() 

if 403 error happens above becameerror handler not invoked , object's state machine left in rootstate.error state , subsequent attempts set property on object fail because of infamous , dreaded:

uncaught error: attempted handle event `willsetproperty` on <radium.contact:ember2286:17> while in state rootstate.error. called {reference: [object object], store: <radium.store:ember3219>, name: name} 

my thinking can override diderror method:

diderror: function(store, type, record, xhr) {   if (xhr.status === 422) {     var json = json.parse(xhr.responsetext),         serializer = get(this, 'serializer'),         errors = serializer.extractvalidationerrors(type, json);      store.recordwasinvalid(record, errors);   } else {     this._super.apply(this, arguments);   } }, 

my question how object usable state after state machine has transitioned rootstate.error.


Comments