Sha256: f239f6968d4f232062b33d661b8fc7d3209fb4cb6c052b200ff37f04f06601ee
Contents?: true
Size: 1.48 KB
Versions: 4
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 ||= Nori.parse(http.body)[:envelope][: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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
savon-1.2.0 | lib/savon/soap/fault.rb |
savon-1.1.0 | lib/savon/soap/fault.rb |
savon-1.0.0 | lib/savon/soap/fault.rb |
savon-0.9.14 | lib/savon/soap/fault.rb |