Skip to content

Commit

Permalink
added exception_notifiable_pass_through and notifiable_pass_through f…
Browse files Browse the repository at this point in the history
…or hoptoad
  • Loading branch information
pboling committed May 13, 2010
1 parent c6d36c3 commit a1ec760
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
21 changes: 21 additions & 0 deletions lib/exception_notification/exception_notifiable.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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?
Expand Down
20 changes: 20 additions & 0 deletions lib/exception_notification/notifiable.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
1 change: 0 additions & 1 deletion lib/exception_notification/notifiable_helper.rb
Expand Up @@ -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}" : ""
Expand Down
2 changes: 0 additions & 2 deletions lib/exception_notification/notifier.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions rails/init.rb
@@ -1,4 +1,3 @@
puts "Begin Loading ExceptionNotification"
require 'rake'
require 'rake/tasklib'
require "action_mailer"
Expand All @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion super_exception_notifier.gemspec
Expand Up @@ -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"]
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit a1ec760

Please sign in to comment.