Ember CLI + Ember数据:如何处理错误消息

时间:2014-09-20 18:48:23

标签: ember.js coffeescript ember-data ember-cli

我正在尝试根据发生错误时服务器的响应为用户提供有用的反馈。默认情况下,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值显示条件错误消息?

0 个答案:

没有答案