向用户显示 global/misc 错误消息
Display global/misc error message to user
我正在尝试为 Ember 中的用户显示错误消息。有没有办法从 Logger
做到这一点?我读过有关错误子状态的信息,但我认为只有在转换出现错误时才会显示。有没有办法在 ApplicationController 中将 属性 设置为错误消息对象(从而将其显示在模板中)?如果 AJAX 调用中出现错误、错误或其他问题,我希望通知用户出现问题。
Coffeescript:
Ember.Logger.error = (message, cause, stack) ->
console.error(message, cause, stack) #show in console
Raygun.send(new Error(message), null, { cause: cause, stack: stack }) #log error on server
# how do I display the error message to user?, THIS DOESN'T WORK b/c "this" is undefined:
@container.lookup('controller:main').set('errorObjetct', message)
我在 ember-cli 中使用 Ember 1.11.1。
有人对此有什么建议吗?
布莱恩
感谢@blessenm link。它并不完全适用,因为在 Ember-CLI 中我没有引用全局应用程序变量,它确实提醒我 initialize
函数传递了 "container" 对象。因此,我已经能够让它像这样工作:
Ember.Logger.error = (message, cause, stack) ->
console.error(message, cause, stack) #show in console
Raygun.send(new Error(message), null, { cause: cause, stack: stack }) #log error on server
# SOLUTION:
container.lookup('route:application').set('errorObject', message)
这在 initializers/error-handling.coffee
的 initialize
函数中运行。
我正在尝试为 Ember 中的用户显示错误消息。有没有办法从 Logger
做到这一点?我读过有关错误子状态的信息,但我认为只有在转换出现错误时才会显示。有没有办法在 ApplicationController 中将 属性 设置为错误消息对象(从而将其显示在模板中)?如果 AJAX 调用中出现错误、错误或其他问题,我希望通知用户出现问题。
Coffeescript:
Ember.Logger.error = (message, cause, stack) ->
console.error(message, cause, stack) #show in console
Raygun.send(new Error(message), null, { cause: cause, stack: stack }) #log error on server
# how do I display the error message to user?, THIS DOESN'T WORK b/c "this" is undefined:
@container.lookup('controller:main').set('errorObjetct', message)
我在 ember-cli 中使用 Ember 1.11.1。
有人对此有什么建议吗?
布莱恩
感谢@blessenm link。它并不完全适用,因为在 Ember-CLI 中我没有引用全局应用程序变量,它确实提醒我 initialize
函数传递了 "container" 对象。因此,我已经能够让它像这样工作:
Ember.Logger.error = (message, cause, stack) ->
console.error(message, cause, stack) #show in console
Raygun.send(new Error(message), null, { cause: cause, stack: stack }) #log error on server
# SOLUTION:
container.lookup('route:application').set('errorObject', message)
这在 initializers/error-handling.coffee
的 initialize
函数中运行。