I am building an ember.js application and am hung up on authentication. The json rest backend is rails. Every request is authenticated using a session cookie (warden).
As of the current version of Ember Data (1.0 beta) you can override the ajaxError
method of DS.RESTAdapter
:
App.ApplicationAdapter = DS.RESTAdapter.extend({
ajaxError: function(jqXHR) {
var error = this._super(jqXHR);
if (jqXHR && jqXHR.status === 401) {
#handle the 401 error
}
return error;
}
});
Note that you should call @_super
, especially if you are overriding one of the more complex adapters like DS.ActiveModelAdapter
, which handles 422 Unprocessable Entity
.