0

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

1 回答 1

0

从 ember 1.0 开始,事件哈希被重命名为操作。路由的错误处理程序应该在操作哈希中。所以:

FullCircle.ApplicationRoute = Ember.Route.extend
  actions: 
    error: (reason, transition) ->
      alert reason
    logout: ->
      ...
于 2013-09-08T16:26:26.763 回答