Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow setting the ignore list off for exceptions on a per exception l…

…evel.
  • Loading branch information...
commit 55f178e4a258696a64e379ffeac506aa9961894d 1 parent 67ab18d
@rsanheim authored
View
4 CHANGELOG.markdown
@@ -1,5 +1,9 @@
# Changelog
+### 0.8.5
+ - Allow setting the ignore list off for exceptions on a per
+ exception level.
+
### 0.8.4
- Log ignored exceptions
View
19 examples/lib/chatterbox/exception_notification_example.rb
@@ -17,6 +17,12 @@
Chatterbox::ExceptionNotification.configure { |c| c.ignore = Chatterbox::ExceptionNotification.default_ignored_exceptions }
end
+ it "does not notify" do
+ Chatterbox::ExceptionNotification.configure { |c| c.ignore << RuntimeError }
+ Chatterbox.expects(:notify).never
+ Chatterbox::ExceptionNotification.handle(:exception => RuntimeError.new)
+ end
+
it "returns nil for explicit exception" do
Chatterbox::ExceptionNotification.configure { |c| c.ignore << RuntimeError }
Chatterbox::ExceptionNotification.handle(RuntimeError.new).should be_nil
@@ -32,9 +38,22 @@
Chatterbox.logger.expects(:debug).once
Chatterbox::ExceptionNotification.handle(RuntimeError.new)
end
+
+ describe "with the ignore list manually turned off" do
+ it "notifies" do
+ Chatterbox::ExceptionNotification.configure { |c| c.ignore << RuntimeError }
+ Chatterbox.expects(:notify)
+ Chatterbox::ExceptionNotification.handle(:exception => RuntimeError.new, :use_ignore_list => false)
+ end
+ end
end
describe "when not on ignore list" do
+ it "notifies" do
+ Chatterbox.expects(:notify)
+ Chatterbox::ExceptionNotification.handle(:exception => Exception.new)
+ end
+
it "logs nothing" do
Chatterbox.logger.expects(:debug).never
Chatterbox::ExceptionNotification.handle(:exception => Exception.new)
View
18 lib/chatterbox/exception_notification.rb
@@ -11,7 +11,7 @@ module ExceptionNotification
# * Objects are simply treated as a 'summary' message were an exception may not be necessary
def handle(args)
hsh = normalize_to_hash(args)
- return if on_ignore_list?(hsh[:exception])
+ return if use_ignore_list?(hsh) && on_ignore_list?(hsh[:exception])
hsh = Extracter.wrap(hsh)
hsh = RailsExtracter.wrap(hsh)
hsh = Presenter.render(hsh)
@@ -26,6 +26,14 @@ def normalize_to_hash(args)
end
end
+ # Check to see if we should use ignore list for this exception -
+ # first use the value from the passed in options, otherwise
+ # use the configuration value (which defaults to true)
+ def use_ignore_list?(hsh)
+ return hsh[:use_ignore_list] if hsh.key?(:use_ignore_list)
+ configuration.use_ignore_list
+ end
+
def on_ignore_list?(exception)
ignored = configuration.ignore.include?(exception.class) ||
configuration.ignore.include?(exception.class.to_s)
@@ -37,8 +45,14 @@ def log_ignored_exception(exception)
Chatterbox.logger.debug { %[Chatterbox::ExceptionNotification ignoring exception: "#{exception}" as its on the ignore list] }
end
+ # Default configuration for ExceptionNotification
+ # :ignore => array of exceptions to ignore by default
+ # :use_ignore_list => whether to use the ignore list -
+ # defaults to true, and can be overidden on per exception level
def configuration
- @configuration ||= OpenStruct.new(:ignore => default_ignored_exceptions)
+ @configuration ||= OpenStruct.new(
+ :ignore => default_ignored_exceptions,
+ :use_ignore_list => true)
end
# Configure ExceptionNotification
Please sign in to comment.
Something went wrong with that request. Please try again.