views:

398

answers:

4

i am testing an application built with rails and from time to time get bugs

when it happens, ActionView::TemplateError occurs and gets logged in log/production.log

how do i catch it and f.ex. send myself by email whenever it happens somewhere in the app?

what is the best way to do that?

f.ex. in ApplicationController with some sort of before_filter?

the code would be, i imagine

before_filter :app_error_catch

def app_error_catch
 begin
  rescue ActionView::TemplateError
  Mailer.deliver_apperror(errormessage)
 end
end

is that close to truth? and how do i get the "errormessage"?

thank you

+2  A: 

Have you looked at [exception_notifier][1] or hoptoad? exception_notifier is a plugin that will send an email on an exception, complete with backtrace.

Hoptoad is a website that collects information about your application's exceptions.

Jeff Paquette
+1  A: 

You don't have to write this yourself - there are plugins built to do this. As suggested by flyfishr64, exception_notifier is widely used.

Go through the following (short) screencast and see which solution you like the best.

arnab
+1  A: 

Along the lines of flyfishr64's answer, there's also the lovely Exceptional

James A. Rosen
Awesome, I've been looking for Exceptional.. I forgot what it was called.
Jeff Paquette
+1  A: 

There are several tools/services you can use.

Third-party services:

Plugins:

Custom

You can easily integrate a custom feature using rescue_from and rescue_action_in_public methods.

Simone Carletti