13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/vat_info/query.rb', line 13
def self.call(request, endpoint, wsdl = WSDL, timeout = TIMEOUT)
client = Savon.client(wsdl: wsdl, open_timeout: timeout)
begin
response = client.call(endpoint, xml: request)
if response.success?
VatInfo::Response.new(status_code: 200, raw: response.body)
else
VatInfo::Response.new(status_code: SERVICE_UNAVAILABLE)
end
rescue Savon::HTTPError => e
if e.to_s.include?('sorry-page.html')
VatInfo::Response.new(status_code: SERVICE_UNAVAILABLE)
else
raise e
end
rescue Net::OpenTimeout
VatInfo::Response.new(status_code: REQUEST_TIME_OUT)
rescue Savon::SOAPFault => e
raise SchemaError, 'The SOAP schema of VAT service may have changed. Go to '\
"#{DOCS} to verify. Original error: #{e}"
end
end
|