Commit 15e3b93

mo khan <mo@mokhan.ca>
2017-02-18 22:16:45
add exception notification.
1 parent 53b6726
Changed files (5)
app/controllers/concerns/error_handleable.rb
@@ -0,0 +1,19 @@
+module ErrorHandleable
+  extend ActiveSupport::Concern
+
+  included do
+    before_action do |controller|
+      if controller.send(:current_user)
+        append_exception_data({
+          current_user: current_user
+        })
+      end
+    end
+  end
+
+  private
+
+  def append_exception_data(data = {})
+    request.env["exception_notifier.exception_data"] = data
+  end
+end
app/controllers/application_controller.rb
@@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base
   include Authenticatable
   include Internationalizationable
   include Pageable
+  include ErrorHandleable
   # Prevent CSRF attacks by raising an exception.
   # For APIs, you may want to use :null_session instead.
   protect_from_forgery with: :exception
config/environments/production.rb
@@ -98,4 +98,11 @@ Rails.application.configure do
     authentication: :login,
     enable_starttls_auto: true
   }
+
+  Rails.application.config.middleware.use ExceptionNotification::Rack, email: {
+    deliver_with: :deliver_later, # Rails >= 4.2.1 do not need this option since it defaults to :deliver_now
+    email_prefix: "[PRODUCTION] ",
+    sender_address: %{"notifier" <notifier@stronglifters.com>},
+    exception_recipients: ENV['EXCEPTION_NOTIFICATION_EMAILS'].split(',').join(' ') %w{mo@mokhan.ca}
+  }
 end
Gemfile
@@ -17,6 +17,7 @@ source "https://rubygems.org" do
   gem "database_cleaner", group: :test
   gem "dotenv-rails"
   gem "email_validator"
+  gem "exception_notification"
   gem "factory_girl_rails", group: :test
   gem "ffaker", group: :test
   gem "flamegraph", group: :development
@@ -33,8 +34,9 @@ source "https://rubygems.org" do
   gem "i18n-tasks", group: :development
   gem "jbuilder", "~> 2.5"
   gem "jquery-rails"
-  gem "listen", "~> 3.0.5"
+  gem "jwt"
   gem "kaminari"
+  gem "listen", "~> 3.0.5"
   gem "meta_request", group: :development
   gem "pg"
   gem "poltergeist", group: :test
@@ -70,7 +72,6 @@ source "https://rubygems.org" do
   gem "web-console", group: :development
   gem "webmock", group: :test
   gem "yelp"
-  gem "jwt"
 end
 
 source "https://rails-assets.org" do
Gemfile.lock
@@ -140,6 +140,9 @@ GEM
       activemodel
     equalizer (0.0.11)
     erubis (2.7.0)
+    exception_notification (4.2.1)
+      actionmailer (>= 4.0, < 6)
+      activesupport (>= 4.0, < 6)
     execjs (2.7.0)
     factory_girl (4.7.0)
       activesupport (>= 3.0.0)
@@ -445,6 +448,7 @@ DEPENDENCIES
   database_cleaner!
   dotenv-rails!
   email_validator!
+  exception_notification!
   factory_girl_rails!
   ffaker!
   flamegraph!