I'm using the Rails exception_notification plugin in my app and find it very useful.
However, there are occasions when I want to catch an exception and deal with it gracefully but still would like to receive the exception notification email. It only seems to send for uncaught exceptions it seems.
Does anyone know how to force send the email for when you've already caught the exception?
I figured out how to do this. Here's the code that you would put in your controller to trigger the email.
For the Rails 2.3 version of the Exception_Notification plugin:
begin
10 / 0
rescue Exception => e
ExceptionNotifier.deliver_exception_notification(e, self, request)
end
For the Rails 3 version of the Exception_Notification plugin:
begin
10 / 0
rescue Exception => e
ExceptionNotifier::Notifier.exception_notification(request.env, e).deliver
end
For the Rails 4 version (currently v4.0.1 of the exception_notification gem):
begin
some code...
rescue => e
ExceptionNotifier.notify_exception(e)
ExceptionNotifier.notify_exception(e, env: request.env, data: { message: "oops" })
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With