2

I can see in the Savon log that my SOAP faults contain XML like this:

<errorCode>666</errorCode><errorDescription>some evil error</errorDescription>

Does anyone know how to parse the error code and description out of the response? Sorry if this is a stupid question, but I've tried everything, and I haven't been able to find any documentation on this.

Mike Conigliaro
  • 1,144
  • 1
  • 13
  • 28

3 Answers3

2

I believe you are looking for this:

def your_method(credentials)
  # your client call here
rescue Savon::SOAPFault => error
  fault_code = error.to_hash[:fault][:faultcode]
  raise CustomError, fault_code
end

Got this solution from Savon documentation.

Thanks!

rony36
  • 3,277
  • 1
  • 30
  • 42
1

For the record, the only way I was able to do this was by disabling Savon exceptions:

Savon::Response.raise_errors = false

After doing this, I had to check response.soap_fault? after each SOAP call to see if there was an error. Then I could access the error details using response.to_hash.

Mike Conigliaro
  • 1,144
  • 1
  • 13
  • 28
0

I use this patch:

module Savon
  class SOAPFault

    def soap_error_code
      fault = nori.find(to_hash, 'Fault')
      if nori.find(fault, 'faultcode')
        nori.find(fault, 'faultcode').to_i
      elsif nori.find(fault, 'Code')
        nori.find(fault, 'Code', 'Value').to_i
      end
    end

  end
end

Then in controller:

begin
 # do something
rescue Savon::SOAPFault => e
  raise CustomError, e.soap_error_code
end
workgena
  • 31
  • 4