Skip to content

Commit

Permalink
Allow skipping report generation using exception property (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cawllec authored and kattrali committed Dec 11, 2017
1 parent 6983f98 commit 2925f69
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/bugsnag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def notify(exception, auto_notify=false, &block)
return
end

if exception.respond_to?(:skip_bugsnag) && exception.skip_bugsnag
configuration.debug("Not notifying due to skip_bugsnag flag")
return
end

report = Report.new(exception, configuration, auto_notify)

# If this is an auto_notify we yield the block before the any middleware is run
Expand Down
8 changes: 8 additions & 0 deletions spec/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,14 @@ def gloops
}
end

it 'does not notify if skip_bugsnag is true' do
exception = BugsnagTestException.new("It crashed")
exception.skip_bugsnag = true
Bugsnag.notify(exception)
expect(Bugsnag).not_to have_sent_notification
end


if defined?(JRUBY_VERSION)

it "should work with java.lang.Throwables" do
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
require 'rspec/expectations'
require 'rspec/mocks'

class BugsnagTestException < RuntimeError; end
class BugsnagTestException < RuntimeError
attr_accessor :skip_bugsnag
end

def get_event_from_payload(payload)
expect(payload["events"].size).to eq(1)
Expand Down

0 comments on commit 2925f69

Please sign in to comment.