我无法让我的ApplicationRoute处理错误。 401或500(来自登录操作)来自服务器的响应未在我的ApplicationRoute中触发错误事件。请帮忙! 我可以在控制台日志中看到401或500错误。
FullCircle.ApplicationRoute = Ember.Route.extend
events:
error: (reason, transition) ->
alert reason
actions:
logout: ->
this.controllerFor('application').logged_out()
delete localStorage.authToken
this.transitionTo 'login'
FullCircle.LoginRoute = Ember.Route.extend
actions:
login: ->
self = this
loginController = @controllerFor 'login'
data = loginController.getProperties("username", "password")
# this would normally be done asynchronously
$.post("/login", data).then (response) ->
alert response.message
if response.user
localStorage.authToken = response.token
applicationController = self.controllerFor 'application'
transition = applicationController.get 'savedTransition'
# set isLoggedIn so the UI shows the logout button
applicationController.logged_in()
# if the user was going somewhere, send them along, otherwise
# default to `/posts`
if transition
transition.retry()
else
self.transitionTo '/documents'
答案 0 :(得分:0)
从ember 1.0开始,事件哈希被重命名为actions。路由的错误处理程序应该在操作哈希中。所以:
FullCircle.ApplicationRoute = Ember.Route.extend
actions:
error: (reason, transition) ->
alert reason
logout: ->
...