Sha256: bf3cc2a1558de3d300734f808f01553b8f128c818035737ceb2287e25988344b
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
require "savon" module Savon class SOAPFault < Error def self.present?(http, xml = nil) xml ||= http.body fault_node = xml.include?("Fault>") soap1_fault = xml.include?("faultcode>") && xml.include?("faultstring>") soap2_fault = xml.include?("Code>") && xml.include?("Reason>") fault_node && (soap1_fault || soap2_fault) end def initialize(http, nori, xml = nil) @xml = xml @http = http @nori = nori end attr_reader :http, :nori, :xml def to_s fault = nori.find(to_hash, 'Fault') message_by_version(fault) end def to_hash parsed = nori.parse(xml || http.body) nori.find(parsed, 'Envelope', 'Body') end private def message_by_version(fault) if nori.find(fault, 'faultcode') code = nori.find(fault, 'faultcode') text = nori.find(fault, 'faultstring') "(#{code}) #{text}" elsif nori.find(fault, 'Code') code = nori.find(fault, 'Code', 'Value') text = nori.find(fault, 'Reason', 'Text') "(#{code}) #{text}" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
savon-2.8.1 | lib/savon/soap_fault.rb |
savon-2.8.0 | lib/savon/soap_fault.rb |