bmh*_*old 7 ember.js ember-data
有关处理401错误的任何想法?
在应用程序初始化程序中,我推迟准备并通过ember-data获取当前用户.如果我收到401应用程序死亡并变得无法使用.我想处理这个错误,然后进行推进.我似乎无法找到解决方法.任何信息,将不胜感激!
请点击这里:https://gist.github.com/unknpwn/6126462
我注意到这里有类似的话题,但似乎已经过时了.
Application.initializer
不是放置此逻辑的正确位置。它是同步的,其目的是执行诸如将自定义对象添加到 IOC 容器等操作。此代码更model
适合ApplicationRoute
.
App.ApplicationRoute = Ember.Route.extend({
beforeModel: function() {
return App.User.find({ filter: "authenticated" });
},
setupController: function(controller, model) {
controller.set('loggedIn', true);
controller.set('currentUser', model);// or some property of that model
},
events: function() {
error: function(err) {
// error handler called in case of an error.
// show the error message to user here
// or transition to another route
}
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2589 次 |
最近记录: |