500 error no problem. Get an email about it!

YOU’RE BETTER OFF USING A SERVICE LIKE HONEYBADGER. IT WILL APPEAR YOU NEED TO PAY FOR HONEYBADGER, BUT YOU CAN SIGN UP FOR FREE, NO CC REQUIRED, AND ONCE YOUR TRIAL ENDs, YOU’LL BE DOWNGRADED TO HAVING ONE APPLICATION, NO COST.

Rails 4, Heroku, Exception Notifier

Errors happen, even if you’ve got a test suite for your application. Rails out of the box will not notify you of 500 errors. This tutorial assumes you’ve already created a heroku application.

$ heroku addons:create sendgrid:starter
# config/environment.rb:

ActionMailer::Base.smtp_settings = {
  :address        => 'smtp.sendgrid.net',
  :port           => '587',       
  :authentication => :plain,
  :user_name      => ENV['SENDGRID_USERNAME'],
  :password       => ENV['SENDGRID_PASSWORD'],
  :domain         => 'heroku.com',
  :enable_starttls_auto => true
}

In the following file, you’ll need to update AppName to your application name. So if you created your application rails new RabbitApp, your AppName will be RabbitApp. You’ll also need to update your_email@example.com.

# config/initializers/exception_notification.rb:
AppName::Application.config.middleware.use ExceptionNotification::Rack,
  :email => {
    :email_prefix => "[AppName] ",
    :sender_address => %{"notifier" },
    :exception_recipients => %w{your_email@example.com}
  }
# Gemfile:
gem 'exception_notification'
# config/environments/production.rb:

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true

Thank you to Komgata for writing the first tutorial

Post Content