From a1ec760d1d0cdb3e431b4e567e27d6ed33c9525e Mon Sep 17 00:00:00 2001 From: pboling Date: Thu, 13 May 2010 19:04:40 -0400 Subject: [PATCH] added exception_notifiable_pass_through and notifiable_pass_through for hoptoad --- .../exception_notifiable.rb | 21 +++++++++++++++++++ lib/exception_notification/notifiable.rb | 20 ++++++++++++++++++ .../notifiable_helper.rb | 1 - lib/exception_notification/notifier.rb | 2 -- rails/init.rb | 3 --- super_exception_notifier.gemspec | 15 ++++++++++++- 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/lib/exception_notification/exception_notifiable.rb b/lib/exception_notification/exception_notifiable.rb index 790e5600..448fdd89 100644 --- a/lib/exception_notification/exception_notifiable.rb +++ b/lib/exception_notification/exception_notifiable.rb @@ -31,6 +31,9 @@ def self.included(base) # Since there is no concept of locality from a request here allow user to explicitly define which env's are noisy (send notifications) base.cattr_accessor :exception_notifiable_noisy_environments base.exception_notifiable_noisy_environments = [:production] + + base.cattr_accessor :exception_notifiable_pass_through + base.exception_notifiable_pass_through = false end module ClassMethods @@ -117,6 +120,7 @@ def rescue_with_handler(exception) # Send Web Hook requests ExceptionNotification::HooksNotifier.deliver_exception_to_web_hooks(ExceptionNotification::Notifier.config, exception, self, request, data, the_blamed) if send_web_hooks end + pass_it_on(exception) to_return end @@ -157,6 +161,23 @@ def notify_and_render_error_template(status_cd, request, exception, file_path, v # deliver raises an exception, we don't call render twice. # Render the error page to the end user render_error_template(file_path, status) + pass_it_on(exception, request) + end + + def pass_it_on(exception, request = nil) + begin + request ||= {:params => {}} + case self.class.exception_notifiable_pass_through + when :hoptoad then + HoptoadNotifier.notify(exception, {:request => request}) + puts "[PASS-IT-ON] HOPTOAD NOTIFIED" if verbose + else + puts "[PASS-IT-ON] NO" if verbose + #nothing + end + rescue + #nothing + end end def is_local? diff --git a/lib/exception_notification/notifiable.rb b/lib/exception_notification/notifiable.rb index 033b9179..ef99c1ed 100644 --- a/lib/exception_notification/notifiable.rb +++ b/lib/exception_notification/notifiable.rb @@ -17,6 +17,9 @@ def self.included(base) # Since there is no concept of locality from a request here allow user to explicitly define which env's are noisy (send notifications) base.cattr_accessor :notifiable_noisy_environments base.notifiable_noisy_environments = [:production] + + base.cattr_accessor :notifiable_pass_through + base.notifiable_pass_through = false end module ClassMethods @@ -86,6 +89,23 @@ def rescue_with_hooks(exception) perform_exception_notify_mailing(exception, data, nil, the_blamed, verbose, rejected_sections) if send_email # Send Web Hook requests ExceptionNotification::HooksNotifier.deliver_exception_to_web_hooks(ExceptionNotification::Notifier.config, exception, self, request, data, the_blamed) if send_web_hooks + pass_it_on(exception) + end + + def pass_it_on(exception, request = nil) + begin + request ||= {:params => {}} + case self.class.notifiable_pass_through + when :hoptoad then + HoptoadNotifier.notify(exception, {:request => request}) + puts "[PASS-IT-ON] HOPTOAD NOTIFIED" if verbose + else + puts "[PASS-IT-ON] NO" if verbose + #nothing + end + rescue + #nothing + end end def is_local? #like asking is_silent? diff --git a/lib/exception_notification/notifiable_helper.rb b/lib/exception_notification/notifiable_helper.rb index f08b55f7..07695bfc 100644 --- a/lib/exception_notification/notifiable_helper.rb +++ b/lib/exception_notification/notifiable_helper.rb @@ -35,7 +35,6 @@ def verbose_output(exception, status_cd, file_path, send_email, send_web_hooks, puts "[ERROR FILE PATH] #{file_path.inspect}" puts "[ERROR EMAIL] #{send_email ? "YES" : "NO"}" puts "[ERROR WEB HOOKS] #{send_web_hooks ? "YES" : "NO"}" - puts "[COMPAT MODE] #{ExceptionNotification::NotifierHelper::COMPAT_MODE ? "YES" : "NO"}" puts "[THE BLAMED] #{the_blamed}" puts "[SECTIONS] #{ExceptionNotification::Notifier.sections_for_email(rejected_sections, request)}" req = request ? " for request_uri=#{request.request_uri} and env=#{request.env.inspect}" : "" diff --git a/lib/exception_notification/notifier.rb b/lib/exception_notification/notifier.rb index 7e270f95..d943361a 100644 --- a/lib/exception_notification/notifier.rb +++ b/lib/exception_notification/notifier.rb @@ -66,7 +66,6 @@ def self.filenamify(str) # What is the path of the file we will render to the user based on a given status code? def self.get_view_path_for_status_code(status_cd, verbose = false) file_name = ExceptionNotification::Notifier.get_view_path(status_cd, verbose) - #ExceptionNotifierHelper::COMPAT_MODE ? "#{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/500.html" : "500.html" file_name.nil? ? self.catch_all(verbose) : file_name end @@ -107,7 +106,6 @@ def self.get_view_path(file_name, verbose = false) puts "[FOUND FILE:D] #{File.dirname(__FILE__)}/../../rails/app/views/exception_notifiable/#{file_name}.html.erb" if verbose "#{File.dirname(__FILE__)}/../../rails/app/views/exception_notifiable/#{file_name}.html.erb" elsif File.exist?("#{File.dirname(__FILE__)}/../../rails/app/views/exception_notifiable/#{file_name}.html") - #ExceptionNotifierHelper::COMPAT_MODE ? "#{File.dirname(__FILE__)}/../rails/app/views/exception_notifiable/#{file_name}.html" : "#{status_cd}.html" puts "[FOUND FILE:E] #{File.dirname(__FILE__)}/../../rails/app/views/exception_notifiable/#{file_name}.html" if verbose "#{File.dirname(__FILE__)}/../../rails/app/views/exception_notifiable/#{file_name}.html" else diff --git a/rails/init.rb b/rails/init.rb index f05872c9..7223117d 100644 --- a/rails/init.rb +++ b/rails/init.rb @@ -1,4 +1,3 @@ -puts "Begin Loading ExceptionNotification" require 'rake' require 'rake/tasklib' require "action_mailer" @@ -10,8 +9,6 @@ Object.class_eval do include ExceptionNotification::Notifiable end -puts "Object test: #{Object.respond_to?(:notifiable_noisy_environments) ? 'Pass' : 'Fail'}" -puts "Finished Loading ExceptionNotification" #It appears that the view path is auto-added by rails... hmmm. #if ActionController::Base.respond_to?(:append_view_path) diff --git a/super_exception_notifier.gemspec b/super_exception_notifier.gemspec index 1e4f4504..e0edfddb 100644 --- a/super_exception_notifier.gemspec +++ b/super_exception_notifier.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{super_exception_notifier} - s.version = "3.0.2" + s.version = "3.0.3" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Peter Boling", "Scott Windsor", "Ismael Celis", "Jacques Crocker", "Jamis Buck"] @@ -39,6 +39,19 @@ Gem::Specification.new do |s| "VERSION.yml", "init.rb", "lib/exception_notification.rb", + "lib/exception_notification/consider_local.rb", + "lib/exception_notification/custom_exception_classes.rb", + "lib/exception_notification/custom_exception_methods.rb", + "lib/exception_notification/deprecated_methods.rb", + "lib/exception_notification/exception_notifiable.rb", + "lib/exception_notification/git_blame.rb", + "lib/exception_notification/helpful_hashes.rb", + "lib/exception_notification/hooks_notifier.rb", + "lib/exception_notification/notifiable.rb", + "lib/exception_notification/notifiable_helper.rb", + "lib/exception_notification/notified_task.rb", + "lib/exception_notification/notifier.rb", + "lib/exception_notification/notifier_helper.rb", "rails/app/views/exception_notifiable/400.html", "rails/app/views/exception_notifiable/403.html", "rails/app/views/exception_notifiable/404.html",