Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Exception Notification Plugin - Force send email

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?

like image 906
johnnymire Avatar asked Oct 01 '09 16:10

johnnymire


1 Answers

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
like image 150
johnnymire Avatar answered Nov 14 '22 14:11

johnnymire