我无法让我的 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'