lib/jt-rails-toolbox.rb in jt-rails-toolbox-1.3.1 vs lib/jt-rails-toolbox.rb in jt-rails-toolbox-2.0.0
- old
+ new
@@ -1,28 +1,22 @@
-require 'dotenv/rails-now'
-require 'http_accept_language'
+require 'exception_notification'
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 'exception_notification/rails'
+require 'exception_notification/sidekiq'
+
require 'yaml'
-if Rails.env.development?
- require 'quiet_assets'
-end
-
-# Don't move this require
-require 'airbrake'
-require 'airbrake/sidekiq/error_handler'
-
module JTRailsToolbox
- class Engine < ::Rails::Engine
+ class Railtie < ::Rails::Railtie
initializer "jt-rails-toolbox" do |app|
@params = {}
if ::File.exists?('config/jt-toolbox.yml')
@@ -76,62 +70,18 @@
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 += %w{ActionController::InvalidCrossOriginRequest ActionController::InvalidAuthenticityToken}
+ config.ignored_exceptions += ['ActionController::InvalidCrossOriginRequest', 'ActionController::InvalidAuthenticityToken']
- 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
+ config.add_notifier :email, {
+ email_prefix: @params['exception']['email_prefix'],
+ sender_address: @params['exception']['sender_address'],
+ exception_recipients: @params['exception']['exception_recipients']
+ }
end
end
def configure_mail(app)
ActionMailer::Base.delivery_method = @params['mail']['delivery_method']
@@ -158,17 +108,19 @@
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