Skip to content

Commit

Permalink
Send exception notifications by email
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Oct 31, 2013
1 parent bc85f33 commit d9407fb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ gem 'mini_magick'
gem 'routing_concerns'
gem 'deep_cloneable', '~> 1.5.5'
gem 'rails_config'
gem "exception_notification", "~> 4.0"

# Gems used only for assets and not required
# in production environments by default.
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ GEM
json
erubis (2.7.0)
eventmachine (1.0.3)
exception_notification (4.0.1)
actionmailer (>= 3.0.4)
activesupport (>= 3.0.4)
execjs (1.4.0)
multi_json (~> 1.0)
factory_girl (2.1.2)
Expand Down Expand Up @@ -297,6 +300,7 @@ DEPENDENCIES
devise-encryptable
dropbox-sdk
erubis
exception_notification (~> 4.0)
factory_girl (~> 2.1.0)
factory_girl_rails
google-analytics-rails
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery # See ActionController::RequestForgeryProtection for details
clear_helpers
before_filter :set_current_semester
before_filter :log_additional_data

rescue_from CanCan::AccessDenied do |exception|
raise exception if Rails.env.development?
Expand Down Expand Up @@ -75,4 +76,13 @@ def current_ability
@current_ability ||= Ability.new(current_user, params)
end

def log_additional_data
request.env['exception_notifier.exception_data'] = {
current_user: (current_user if user_signed_in?),
current_semester: current_semester,
current_faculty: (current_faculty if session[:current_faculty_id].present?),
current_department: (current_department if session[:current_department_id].present?),
}
end

end
4 changes: 4 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true

# Enable threaded mode
# config.threadsafe!
Expand All @@ -56,4 +58,6 @@

GA.tracker = Settings.analytics.id

config.middleware.use ExceptionNotification::Rack, Settings.exception_notification.to_hash

end
8 changes: 8 additions & 0 deletions config/initializers/mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# It's required for links generation in emails
Taurus::Application.config.action_mailer.default_url_options = { host: 'taurus.amursu.ru' }

Taurus::Application.config.action_mailer.default_url_options = { :host => 'localhost:3000' } if Rails.env.development?

Taurus::Application.config.action_mailer.delivery_method = :smtp

Taurus::Application.config.action_mailer.smtp_settings = Settings.mailer
8 changes: 8 additions & 0 deletions config/settings.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ mailer:
analytics:
id: UA-39782423-3

exception_notification:
email:
email_prefix: "[TAURUS ERROR] "
sender_address: '"Taurus notifications" <[email protected]>'
exception_recipients:
- [email protected]
- [email protected]

backup:
server:
username: user
Expand Down

0 comments on commit d9407fb

Please sign in to comment.