Question

Can anyone suggest a way to have any application errors in a Padrino app send these errors via email?

I already have the Padrino Mailer configured properly and can send test emails, I just have no idea how to configure the app to send me a report via mail (as well as logging it, of course) whenever an error occurs.

Thanks.

Était-ce utile?

La solution

I ended up using the padrino-contrib gem. With it, you can install the plugin you need (of course you can do it manually also):

padrino-gen plugin exception_notifier

Which will add it to your gem file and also edit your app/app.rb and boot.rb files to load this gem.

Then in app/app.rb you put something like:

register Padrino::Contrib::ExceptionNotifier
  set :exceptions_from,    "noreply@domain.com"
  set :exceptions_to,      "your_address.domain.com"

And that's it.

The nice thing about letting the plugin install it for you is that if you're more familiar with Rails than Padrino (as is my case) this will not only set things up for you, but also show you were the directives need to go.

Hope this helps someone else.

Autres conseils

A good approach should be using exception handlers. Adding a begin..rescue block to your code, and if there is an exception, you send the email and continue to the desired behavior.

def some_action
  begin
    # some code that could go wrong
  rescue SomeExceptionClass => some_variable
    # here you send the email with the errors
    # render stuff, redirect stuff, etc
  end
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top