Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Exception Notifications via email in Rails

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.44k
    Comment on it

    Sending Notifications on Exceptions in Rails


    Hi Friends,
    Let's first discuss about debugging a code. During development, suppose you have pushed some changes, then you need to test each and every functionality to check whether your code breaks or not, which is actually impossible. Suppose some part of your code is throwing exceptions, and you are not aware of that but the end user is facing issues because of that. So it is better to have a solution that automatically sends notifications to the developers and admin's whenever an exception comes in the code.
    In rails we have a beautiful gem exception_notification that does the work for us. The documentation of the gem can be found at Exception Notifier in Rails.

    Here I am explaining how to set up this in your application.


    Step 1: Add the gem to your Gemfile.


    	gem 'exception_notification'

    Step 2: Run the bundle.

    	$ bundle

    Step 3: Configure the action mailer for sending notifications via Email. You can have any configurations for sending emails you like. For sending emails using gmail see this link. Sending Emails in Rails using Gmail. To make exception notifier work, you need to put this code into your production.rb. For testing purpose we are placing the code inside development.rb too.

    	Rails.application.config.middleware.use ExceptionNotification::Rack,
    	  :email => {
    	    :email_prefix => "[PREFIX] ",
    	    :sender_address => %{"notifier" },
    	    :exception_recipients => %w{}

    Step 4: Now you need to enable these lines inside the environment file development.rb

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

    Now whenever their will be an exception in your code an email will be sent automatically to all the emails that are passed in exception_recipients. A project with full integration of exception notifier and email integration can found here Do the following to get an exception mail in that project.

    • Clone the Repository
    • Produce some bugs in the code
    • Run the rails server
    • Place your gmail username and password in config/development.rb
    • Place a reveiver email in the exception_recipients
    • Now whenever you will produce an error in the code, an exception email will be sent to the receiver email

    Exception Notifier can also be integrated with these platforms:

    • Campfire notifier
    • Email notifier
    • HipChat notifier
    • IRC notifier
    • Slack notifier
    • WebHook notifier

    Exception Notifier has several extra options and customizations that you can find here at Exception Notifier in Rails

    Hope you liked this. For more blogs like this Click here.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: