Sha256: 8e70552c5576e11b91e93687257d6df80e577c073977efd96039bc75f0eb0ef9

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

require "savon/error"
require "savon/soap/xml"

module Savon
  module SOAP

    # = Savon::SOAP::Fault
    #
    # Represents a SOAP fault. Contains the original <tt>HTTPI::Response</tt>.
    class Fault < Error

      # Expects an <tt>HTTPI::Response</tt>.
      def initialize(http)
        self.http = http
      end

      # Accessor for the <tt>HTTPI::Response</tt>.
      attr_accessor :http

      # Returns whether a SOAP fault is present.
      def present?
        @present ||= http.body.include?("Fault>") && (soap1_fault? || soap2_fault?)
      end

      # Returns the SOAP fault message.
      def to_s
        return "" unless present?
        @message ||= message_by_version to_hash[:fault]
      end

      # Returns the SOAP response body as a Hash.
      def to_hash
        @hash ||= Savon::SOAP::XML.to_hash http.body
      end

    private

      # Returns whether the response contains a SOAP 1.1 fault.
      def soap1_fault?
        http.body.include?("faultcode>") && http.body.include?("faultstring>")
      end

      # Returns whether the response contains a SOAP 1.2 fault.
      def soap2_fault?
        http.body.include?("Code>") && http.body.include?("Reason>")
      end

      # Returns the SOAP fault message by version.
      def message_by_version(fault)
        if fault[:faultcode]
          "(#{fault[:faultcode]}) #{fault[:faultstring]}"
        elsif fault[:code]
          "(#{fault[:code][:value]}) #{fault[:reason][:text]}"
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
search_biomodel-1.0.0 search_biomodel/ruby/1.8/gems/savon-0.9.2/lib/savon/soap/fault.rb
savon-0.9.2 lib/savon/soap/fault.rb
s-savon-0.8.6 lib/savon/soap/fault.rb
savon-0.9.1 lib/savon/soap/fault.rb
savon-0.9.0 lib/savon/soap/fault.rb
savon-0.8.6 lib/savon/soap/fault.rb