Skip to content

Loading…

Add the ability to pass XML directly to send_to_airbrake #124

Merged
merged 1 commit into from

2 participants

@zanker

Currently you have to serialize the data, pass it to Resque, unserialize it, pass it to send_to_airbrake, which then immediately serializes it again as XML.

Letting people serialize it to XML ahead of time simplifies setting up async reporting and reduces the chance that another error will occur when trying to send a report about the original error.

The only real difference is that if you pass XML, it will now dump XML if Airbrake gets an HTTP error from sending the request, it will dump the XML rather than pretty printed.

@zanker zanker closed this
@zanker zanker reopened this
@shime shime merged commit fa6c1ff into airbrake:master
@shime
airbrake member

:heart: Thanks for this. Yeah, on failure it will print the XML passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 13, 2012
  1. @zanker
Showing with 28 additions and 2 deletions.
  1. +2 −2 lib/airbrake/sender.rb
  2. +26 −0 test/sender_test.rb
View
4 lib/airbrake/sender.rb
@@ -31,9 +31,9 @@ def initialize(options = {})
# Sends the notice data off to Airbrake for processing.
#
- # @param [Notice] notice The notice to be sent off
+ # @param [Notice or String] notice The notice to be sent off
def send_to_airbrake(notice)
- data = notice.to_xml
+ data = notice.respond_to?(:to_xml) ? notice.to_xml : notice
http = setup_http_connection
response = begin
View
26 test/sender_test.rb
@@ -31,6 +31,32 @@ def stub_http(options = {})
http
end
+ should "post to Airbrake with XML passed" do
+ xml_notice = Airbrake::Notice.new(:error_class => "FooBar", :error_message => "Foo Bar").to_xml
+
+ http = stub_http
+
+ sender = build_sender
+ sender.send_to_airbrake(xml_notice)
+
+ assert_received(http, :post) do |expect|
+ expect.with(anything, xml_notice, Airbrake::HEADERS)
+ end
+ end
+
+ should "post to Airbrake with a Notice instance passed" do
+ notice = Airbrake::Notice.new(:error_class => "FooBar", :error_message => "Foo Bar")
+
+ http = stub_http
+
+ sender = build_sender
+ sender.send_to_airbrake(notice)
+
+ assert_received(http, :post) do |expect|
+ expect.with(anything, notice.to_xml, Airbrake::HEADERS)
+ end
+ end
+
should "post to Airbrake when using an HTTP proxy" do
response = stub(:body => 'body')
http = stub(:post => response,
Something went wrong with that request. Please try again.