我可以在Savon日志中看到我的SOAP错误包含这样的XML:
<errorCode>666</errorCode><errorDescription>some evil error</errorDescription>
有谁知道如何从响应中解析错误代码和描述?很抱歉,如果这是一个愚蠢的问题,但我已经尝试了一切,而且我无法找到任何相关的文档。
答案 0 :(得分:1)
为了记录,我能够做到这一点的唯一方法是禁用Savon例外:
Savon::Response.raise_errors = false
执行此操作后,我必须检查response.soap_fault?在每次SOAP调用之后查看是否有错误。然后我可以使用response.to_hash访问错误详细信息。
答案 1 :(得分:1)
我相信你正在寻找这个:
dump("df","")
从def your_method(credentials)
# your client call here
rescue Savon::SOAPFault => error
fault_code = error.to_hash[:fault][:faultcode]
raise CustomError, fault_code
end
documentation获得此解决方案。
谢谢!
答案 2 :(得分:0)
我使用这个补丁:
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
然后在控制器中:
begin
# do something
rescue Savon::SOAPFault => e
raise CustomError, e.soap_error_code
end