我有一个 Rails 4 应用程序并使用 gem exception_notification
。安装了 gem,在 config/environments/production.rb
中如下:
config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[MyProj Error Report] ",
:sender_address => %{"MyProj" <no-reply@myproj.com>},
:exception_recipients => %w{info@myproj.com}
}
no-reply@myproj.com
电子邮件地址不存在,info@myproj.com
是我的真实电子邮件地址。
当生产过程中发生错误时,我没有收到任何有关它的电子邮件。
我还需要添加哪些其他配置信息?
编辑:
config/environments/production.rb
:
Rails.application.configure do
...
MyApp::Application.config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[MyApp_Error] ",
:sender_address => %{"notifier" <notifier@myAppName.com>},
:exception_recipients => %w{your_email_id@gmail.com}
}
end
我用我的真实电子邮件地址修改了代码,但仍然没有成功。在日志中什么都没有 - 当我想获取一个 ID 不存在的记录时,比如 website.com/articles/123345666777
,错误日志中只有以下内容:
ActiveRecord::RecordNotFound (Couldn't find Article with 'id'=123345666777):
app/controllers/articles_controller.rb:175:in `set_article'
最佳答案
ActiveRecord::RecordNotFound
是一个非常特殊的情况(对于路由错误和其他一些错误也是如此)。如果这种异常触发 ExceptionNotifier
发送邮件,我会感到惊讶。在生产环境中,Rails 将通过呈现 404
(未找到)页面来处理此错误,而不是 Rails 无法呈现时会发生的 500
(服务器错误)处理异常。
事实上,在 ExceptionNotifier
中有选项 ignore_exceptions
默认包含此异常。阅读更多关于 ignore_exceptions
option and its defaults 的信息.
关于ruby-on-rails - Rails 4 - 如果出错,异常通知程序不会发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28718186/