1

I have an app which allows users to submit a post to Twitter. It's using Ember.Data with a Django Rest Framework back end. A user posts a Message, which goes to the server, then submits to Twitter, then returns the response back to the client. That part all works fine but I want to build in code to manage the times when the request fails, either on our server or on the request to Twitter.

I've found documentation on an isError state for Models but I'm not sure if this is the correct property I'm looking for.

Here's the code I'm currently implementing:

saveMessage: function(text, postingWindow){
    var acct = Social.Account.find(this.get("id")),
        msg = Social.store.createRecord(
                  Social.Message,
                  {
                      text: text,
                      account: acct,
                      created: new Date()
                  }
              );

    acct.get("messages").addObject(msg);
    Social.store.commit();
}

Basically what I'm trying to accomplish is to hold off displaying the message in the UI until I know I have success from the user. But on the flip side I don't want to wait forever if I can get an error state right away.

commadelimited
  • 5,100
  • 5
  • 38
  • 69
  • if you guys are using the ember-data django rest framework adapter could you verify you pulled in the latest pull request (around error handling specifically) https://github.com/toranb/ember-data-django-rest-adapter/commits/master – Toran Billups Mar 26 '13 at 20:43

2 Answers2

0

Check out my answer here: How should errors be handled when using the Ember.js Data RESTAdapter?

Basically, you can override the callbacks becameError and becameInvalid on a DS.Model subclass. There are other Model lifecycle callbacks that you can hook into. See here: http://emberjs.com/guides/models/model-lifecycle/

Community
  • 1
  • 1
Sherwin Yu
  • 2,940
  • 1
  • 21
  • 37
0

I use something like this:

AdminApp.ApplicationAdapter = DS.RESTAdapter.extend({
    namespace: '',
    host: 'http://localhost/myroomplan_wp/index.php/wp-json',
    ajaxError: function(jqXHR) {
        alert(jqXHR.responseText);
    }
});
bummi
  • 26,435
  • 13
  • 58
  • 97
Epirocks
  • 424
  • 4
  • 11