gpt4 book ai didi

error-handling - Ember ApplicationRoute无法处理错误事件

转载 作者:行者123 更新时间:2023-12-03 08:57:44 25 4
gpt4 key购买 nike

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

最佳答案

从ember 1.0开始,事件哈希已重命名为action。路线的错误处理程序应位于操作哈希中。所以:

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

关于error-handling - Ember ApplicationRoute无法处理错误事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18685186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com