我正在尝试根据发生错误时服务器的响应为用户提供有用的反馈。默认情况下,Ember CLI为error.hbs
提供了一个模板,该模板将其model
设置为从Ember Data promise
调用返回的GET
。我已在模板上配置了错误条件,并希望在控制器中设置这些条件:
{{#if pageNotFound}}
<p>Sorry. The page you requested does not exist.</p>
{{elseif internalServerError}}
<p>An internal server error occured. Please try again.</p>
{{elseif notAuthorized}}
<p>It looks like you are not authorized to view this page. Have you registered and logged in?</p>
{{/if}}
我尝试通过我的ApplicationRoute
设置值但没有成功,as suggested here:
ApplicationRoute = Ember.Route.extend(
actions:
error: (error, transition) ->
errorController = @controllerFor "error"
switch error.status
when 404 then errorController.set("pageNotFound", true)
when 500 then errorController.set("internalServerError", true)
when 403 then errorController.set("notAuthorized", true)
else errorController.set("generic error", true)
@transitionTo "error"
)
但是我看到没有转换,但是当我放入console.log
时,动作功能会触发。
如何根据通用status
路由和模板上的承诺ApplicationError
值显示条件错误消息?