joh*_*ire 18 exception-handling ruby-on-rails
我在我的应用程序中使用Rails exception_notification插件并发现它非常有用.
但是,在某些情况下,我希望捕获异常并优雅地处理它,但仍希望收到异常通知电子邮件.它似乎似乎只发送未捕获的例外.
当你已经发现异常时,是否有人知道如何强制发送电子邮件?
joh*_*ire 30
我想出了如何做到这一点.这是您将在控制器中触发电子邮件的代码.
对于Exception_Notification插件的Rails 2.3版本:
begin
10 / 0
rescue Exception => e
ExceptionNotifier.deliver_exception_notification(e, self, request)
end
Run Code Online (Sandbox Code Playgroud)
对于Exception_Notification插件的Rails 3版本:
begin
10 / 0
rescue Exception => e
ExceptionNotifier::Notifier.exception_notification(request.env, e).deliver
end
Run Code Online (Sandbox Code Playgroud)
对于Rails 4版本(当前为exception_notification gem的v4.0.1):
begin
some code...
rescue => e
ExceptionNotifier.notify_exception(e)
ExceptionNotifier.notify_exception(e, env: request.env, data: { message: "oops" })
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3991 次 |
| 最近记录: |