Have you ever wanted to be one step ahead, and be notified of any unwanted exception before your users have to deal with it? If so, read this article to configure your rails application in just a few steps.
First, we are going to need two gems:
Install them as you would do with any other gem. In my case, I add them to the Gemfile and then run bundle install. Setting them up is as easy as adding a few lines in our environment files, or an initializer config file:
:webhook_url = “YOUR_WEB_HOOK_URL”
But wait, how do I get that YOUR_SLACK_WEB_HOOK_URL?
OK, that was easy, but how can I test that it is working?
Maybe your code is so good that it doesn’t raise an exception. In that case, we can add a rails route to test this functionality. Go to your routes.rb file and add this:
|# Route for testing Exception Notification configurationget “test_exception_notifier” => “application#test_exception_notifier”|
Then, in your application controller:
raise “Test Exception. This is a test exception to make sure the exception notifier is working.”
Finally, visit yourhost/test_exception_notifier and voila! You should receive a slack notification looking something like this:
Slack notification example
In the message, you are going to get a full detail of the exception, including a description, the host’s name, and a full backtrace.
Let us know how this worked for you in the comments!
Are you interested in a project like this?Hire Us