Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'block syntax' on Bugsnag.notify calls #292

Merged
merged 1 commit into from
May 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/bugsnag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,21 @@ def configure(config_hash=nil)
end

# Explicitly notify of an exception
def notify(exception, overrides=nil, request_data=nil)
def notify(exception, overrides=nil, request_data=nil, &block)
notification = Notification.new(exception, configuration, overrides, request_data)

yield(notification) if block_given?

notification.deliver
notification
end

# Notify of an exception unless it should be ignored
def notify_or_ignore(exception, overrides=nil, request_data=nil)
def notify_or_ignore(exception, overrides=nil, request_data=nil, &block)
notification = Notification.new(exception, configuration, overrides, request_data)

yield(notification) if block_given?

unless notification.ignore?
notification.deliver
notification
Expand All @@ -74,10 +79,10 @@ def notify_or_ignore(exception, overrides=nil, request_data=nil)
# Auto notify of an exception, called from rails and rack exception
# rescuers, unless auto notification is disabled, or we should ignore this
# error class
def auto_notify(exception, overrides=nil, request_data=nil)
def auto_notify(exception, overrides=nil, request_data=nil, &block)
overrides ||= {}
overrides.merge!({:severity => "error"})
notify_or_ignore(exception, overrides, request_data) if configuration.auto_notify
notify_or_ignore(exception, overrides, request_data, &block) if configuration.auto_notify
end

# Log wrapper
Expand Down
11 changes: 11 additions & 0 deletions spec/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ def gloops
}
end

it "lets you override severity using block syntax" do
Bugsnag.notify(BugsnagTestException.new("It crashed")) do |notification|
notification.severity = "info"
end

expect(Bugsnag).to have_sent_notification{ |payload|
event = get_event_from_payload(payload)
expect(event["severity"]).to eq("info")
}
end

it "autonotifies errors" do
Bugsnag.auto_notify(BugsnagTestException.new("It crashed"))

Expand Down