Skip to content

Commit

Permalink
add back #soap_fault/#http_error readers to Response
Browse files Browse the repository at this point in the history
These two methods were removed in the big refactoring for the major release.
Add them back since they are the only API to access the errors when the client
is configured with `:raise_errors => false`.

Fixes savonrb#450
  • Loading branch information
pigoz committed May 14, 2013
1 parent e36d6e1 commit fd39c3b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/savon/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ def initialize(http, globals, locals)
@globals = globals
@locals = locals

build_soap_and_http_errors!
raise_soap_and_http_errors! if @globals[:raise_errors]
end

attr_reader :http, :globals, :locals
attr_reader :http, :globals, :locals, :soap_fault, :http_error

def success?
!soap_fault? && !http_error?
Expand Down Expand Up @@ -66,9 +67,14 @@ def xpath(path, namespaces = nil)

private

def build_soap_and_http_errors!
@soap_fault = SOAPFault.new(@http, nori) if soap_fault?
@http_error = HTTPError.new(@http) if http_error?
end

def raise_soap_and_http_errors!
raise SOAPFault.new(@http, nori) if soap_fault?
raise HTTPError.new(@http) if http_error?
raise soap_fault if soap_fault?
raise http_error if http_error?
end

def raise_invalid_response_error!
Expand Down
24 changes: 24 additions & 0 deletions spec/savon/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
end
end

describe "#soap_fault" do
before { globals[:raise_errors] = false }

it "should return nil in case the response seems to be ok" do
soap_response.soap_fault.should be_nil
end

it "should return a SOAPFault in case of a SOAP fault" do
soap_fault_response.soap_fault.should be_a(Savon::SOAPFault)
end
end

describe "#http_error?" do
before { globals[:raise_errors] = false }

Expand All @@ -65,6 +77,18 @@
end
end

describe "#http_error" do
before { globals[:raise_errors] = false }

it "should return nil in case the response seems to be ok" do
soap_response.http_error.should be_nil
end

it "should return a HTTPError in case of an HTTP error" do
soap_response(:code => 500).http_error.should be_a(Savon::HTTPError)
end
end

describe "#header" do
it "should return the SOAP response header as a Hash" do
response = soap_response :body => Fixture.response(:header)
Expand Down

0 comments on commit fd39c3b

Please sign in to comment.