Global Error Handling with Exception Notification
March 20th, 2006
When working in a web environment, it can be difficult to know the health of your application without digging through some log files or worse, waiting for the customer to complain.
Ruby On Rails provides a nice and easy alternative for emailing you whenever an error occurs within your application.
And best of all, it is a plugin called exception_notification, which requires very little effort to roll into your application. To install the exception_notification plugin, just type the following from the root of your rails app:
> ruby script\plugin install exception_notification
And then any controller that you want to notify you of errors needs to include ExceptionNotifiable. In my case, I would like to be notified for all controllers, so I added this into my application controller:
[ruby]class ApplicationController < ActionController::Base
include ExceptionNotifiable[/ruby]
Then, you just need to configure the email address to send the error notifications in your config\environment.rb file:
[ruby]ExceptionNotifier.exception_recipients =
%w(some-admin@email.com another-admin@email.com)[/ruby]
And that's it!
Note: One prerequisite to doing all of this is you must also configure your ActionMailer for sending emails.
Subscribe to the feed!
April 7th, 2007 at 9:46 am
Thank you!
And the first thing I do after “And that’s it!” is how do I test it? (A raw test with an example ActionMailer class works.)
How do I hot-wire my app to fail, then run a test and watch it fail? Or how do I write a functional test
My present attempt (via Rails 1.2.3) to put a raise ‘die’ into the controllers and run the site doesn’t work, and doesn’t throw any errors.
August 8th, 2007 at 2:37 pm
Awesome plugin. I haven’t actually used it but I’m excited to try it out now.
August 29th, 2007 at 5:22 am
Hi I added plug in in my project, configured it like the steps given above. But I am not receiving any mails. can anyone help me what could be missing?
December 13th, 2007 at 6:11 pm
Would be useful to know how to get notifications from cron script/runner exceptions (batch jobs) not just controller actions
December 13th, 2007 at 10:38 pm
Hi Dave,
I agree that would be useful. Perhaps you could just wrap your code in a begin rescue block and call a Notifier method to mail you?
Tom