Error handling Ember ApplicationRoute无法处理错误事件

Error handling Ember ApplicationRoute无法处理错误事件,error-handling,ember.js,Error Handling,Ember.js,我无法让我的ApplicationRoute处理错误。来自服务器的401或500(来自登录操作)响应未在my ApplicationRoute中触发错误事件。请帮忙! 我可以在控制台日志中看到401或500错误 FullCircle.ApplicationRoute = Ember.Route.extend events: error: (reason, transition) -> alert reason actions: logout: -&

我无法让我的ApplicationRoute处理错误。来自服务器的401或500(来自登录操作)响应未在my 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'

从ember 1.0开始,事件哈希被重命名为actions。路由的错误处理程序应位于操作哈希中。因此:

FullCircle.ApplicationRoute = Ember.Route.extend
  actions: 
    error: (reason, transition) ->
      alert reason
    logout: ->
      ...

谢谢你的回复。但我试过了,运气不好。我需要在模型或模型之前输入以捕获错误事件吗?是的,查看您的登录操作,它正在调用
$.post(“/login”,data)
,但只传递一个成功fx。只有当其中一个模型挂钩(如在_model或model之前)抛出错误或返回无法解决的承诺时,才会调用错误事件。看一看embercasts.com关于客户端身份验证的插曲。。。