From 57e045cc905800e19736c74483cfbb74059c6d30 Mon Sep 17 00:00:00 2001 From: James Smith Date: Sun, 17 Apr 2016 14:11:46 -0700 Subject: [PATCH] Add support for 'block syntax' on Bugsnag.notify calls --- lib/bugsnag.rb | 13 +++++++++---- spec/notification_spec.rb | 11 +++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index 66cb695aa..b50dfdd10 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -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 @@ -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 diff --git a/spec/notification_spec.rb b/spec/notification_spec.rb index d365f3f65..5d918a39f 100644 --- a/spec/notification_spec.rb +++ b/spec/notification_spec.rb @@ -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"))