Ember.js 正在使用有关服务器错误和余烬数据的有用信息

Ember.js 正在使用有关服务器错误和余烬数据的有用信息,ember.js,ember-data,Ember.js,Ember Data,如果余烬数据请求失败,人们如何更新应用程序 举例说明: this.get('foo').save().then(function(result){ }).catch(function(error){ //1) how do I know what the server response code was? // (error - does not contain the status code) //assume 'foo' save failed beca

如果余烬数据请求失败,人们如何更新应用程序

举例说明:

this.get('foo').save().then(function(result){

}).catch(function(error){

    //1) how do I know what the server response code was?
    //     (error - does not contain the status code)

    //assume 'foo' save failed because 'bar' model changed on the server
    //2) if I wanted to pass updated 'bar' from the server on failure how can I get
    //     Ember data to update the model?        

});
到目前为止,我的解决方案适用于1,但它有点粗糙,我更喜欢用一种更惯用的方式来处理这个问题

App.ApplicationAdapter = DS.ActiveModelAdapter.extend({
    ajaxError: function(jqXHR) {
       var response = this._super(jqXHR);
       response.status = jqXHR.status;
       return response;
    }
});

在ApplicationRoute中处理事件。在错误响应中的某个地方,您将拥有声明或暗示错误的属性,探测JSON响应并找到执行操作所需的属性thing@MilkyWayJoe:当ember数据出于某种原因处理错误时,它不会通过jqXHR对象,包括状态和其他可能相关的信息,以便消费者采取行动。因此,每个错误对消费者来说都是相同的。