# Handle errors with ember data

**URL:** https://discuss.emberjs.com/t/handle-errors-with-ember-data/5885
**Category:** Ember Data
**Created:** [July 11, 2014, 10:26pm UTC](https://discuss.emberjs.com/t/handle-errors-with-ember-data/5885 "2014-07-11T22:26:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Hummingbird](https://avatars.discourse-cdn.com/v4/letter/h/59ef9b/32.png) [@Hummingbird](https://discuss.emberjs.com/u/Hummingbird)
#### Post date: [July 11, 2014, 10:26pm UTC](https://discuss.emberjs.com/t/handle-errors-with-ember-data/5885/1 "2014-07-11T22:26:17Z")

</div>

I am writing my own adapter for ember data, which uses sockets to communicate with the backend and I have run into an issue with handling server side errors, where records are deleted in ember even though an error has been returned.

Upon a server side error I call within the adapter:

```
Ember.run(null, reject, json);

```

where json is the actual description about the error.

When I check the debugger I can see that this bubbles up to:

```
store.recordWasError(record, reason);

```

within the \_commit function. However it looks like the record is even deleted before it reaches that function.

I have also tried to wrap my error within `new DS.InvalidError(json)`, however it seems like ember data expects to be told which fields are in error and complains about the object not having fields it expects.

How do I handle server side errors in a way that I can at least display something like a pop up to the user and the action may be retried? For instance if I just throw an exception during a delete operation, ember data does not seem to notice that and when the button is clicked again, ember complains that the model is already being deleted.

I noticed that I can do something like this in my route and trigger to rollback manually, however I don’t really want to repeat myself on every entity that I want to delete and it seems a little strange that ember data gets out of sync, when I don’t do this:

```
actions: {
    deleteGroup: function(group) {
      group.destroyRecord().then(function() {
        // transition back to the groups route when delete is complete
        this.get('controller').transitionToRoute('groups');
      }.bind(this), function() {
        group.rollback();
      });
    }
  }

```

So, I guess I must be doing something wrong…?
