lib/jt-rails-toolbox.rb in jt-rails-toolbox-1.2.4 vs lib/jt-rails-toolbox.rb in jt-rails-toolbox-1.3.0

- old
+ new

@@ -1,26 +1,28 @@ -require 'exception_notification' +require 'dotenv/rails-now' +require 'http_accept_language' require 'paperclip' require 'sidekiq' require 'validates_email_format_of' require 'rails_i18n' require 'jt-rails-meta' require 'jt-rails-generator-user' require 'jt-rails-tokenizable' +require 'yaml' + if Rails.env.development? require 'quiet_assets' end -require 'exception_notification/rails' -require 'exception_notification/sidekiq' +# Don't move this require +require 'airbrake' +require 'airbrake/sidekiq/error_handler' -require 'yaml' - module JTRailsToolbox - class Railtie < ::Rails::Railtie + class Engine < ::Rails::Engine initializer "jt-rails-toolbox" do |app| @params = {} if ::File.exists?('config/jt-toolbox.yml') @@ -74,18 +76,62 @@ end def configure_exception_notification(app) return if @params['exception'].nil? + if @params['exception']['airbrake'] + + Airbrake.configure do |c| + if @params['exception']['airbrake']['host'] + c.host = @params['exception']['airbrake']['host'] + end + + c.project_id = @params['exception']['airbrake']['project_id'] + c.project_key = @params['exception']['airbrake']['project_key'] + + c.environment = Rails.env + + if @params['exception']['airbrake']['ignore_environments'] + c.ignore_environments = @params['exception']['airbrake']['ignore_environments'] + else + c.ignore_environments = %w(development test) + end + end + + # Default ignored exceptions in Exception Notification + exceptions_to_ignore = %w{ActiveRecord::RecordNotFound Mongoid::Errors::DocumentNotFound AbstractController::ActionNotFound ActionController::RoutingError ActionController::UnknownFormat ActionController::UrlGenerationError} + + # Additionnal exceptions to ignore + exceptions_to_ignore.push *%w{ActionController::InvalidCrossOriginRequest ActionController::InvalidAuthenticityToken} + + Airbrake.add_filter do |notice| + if notice[:errors].any? { |error| exceptions_to_ignore.include?(error[:type]) } + notice.ignore! + end + end + end + + require 'exception_notification' + require 'exception_notification/rails' + require 'exception_notification/sidekiq' + ExceptionNotification.configure do |config| - config.ignored_exceptions += ['ActionController::InvalidCrossOriginRequest', 'ActionController::InvalidAuthenticityToken'] + config.ignored_exceptions += %w{ActionController::InvalidCrossOriginRequest ActionController::InvalidAuthenticityToken} - config.add_notifier :email, { - email_prefix: @params['exception']['email_prefix'], - sender_address: @params['exception']['sender_address'], - exception_recipients: @params['exception']['exception_recipients'] - } + if @params['exception']['slack'] + config.add_notifier :slack, { + webhook_url: params['exception']['slack']['webhook_url'], + } + end + + if @params['exception']['exception_recipients'] + config.add_notifier :email, { + email_prefix: @params['exception']['email_prefix'], + sender_address: @params['exception']['sender_address'], + exception_recipients: @params['exception']['exception_recipients'] + } + end end end def configure_mail(app) ActionMailer::Base.delivery_method = @params['mail']['delivery_method'] @@ -112,19 +158,17 @@ end def configure_sidekiq(app) Sidekiq.configure_server do |config| config.redis = { url: @params['sidekiq']['redis_url'], namespace: @params['sidekiq']['namespace'] } - - config.error_handlers << Proc.new {|ex, ctx_hash| ExceptionNotifier.notify_exception(ex, data: ctx_hash) } end Sidekiq.configure_client do |config| config.redis = { url: @params['sidekiq']['redis_url'], namespace: @params['sidekiq']['namespace'] } end ActiveJob::Base.queue_adapter = :sidekiq end end - + end \ No newline at end of file