Class: Common::Client::Middleware::Response::SOAPParser

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/common/client/middleware/response/soap_parser.rb

Direct Known Subclasses

HCA::SOAPParser

Instance Method Summary collapse

Instance Method Details

#doc_includes_error?(doc) ⇒ Boolean (private)

Returns:

  • (Boolean)


38
39
40
# File 'lib/common/client/middleware/response/soap_parser.rb', line 38

def doc_includes_error?(doc)
  !doc.locate('env:Envelope/env:Body/env:Fault').empty?
end

#ensure_xml_prolog(xml) ⇒ Object (private)



33
34
35
36
# File 'lib/common/client/middleware/response/soap_parser.rb', line 33

def ensure_xml_prolog(xml)
  xml = xml.dup.prepend('<?xml version="1.0" encoding="UTF-8"?>') unless xml.match?(/^<\?xml/)
  xml
end

#log_error_details(env) ⇒ Object (private)



25
26
27
# File 'lib/common/client/middleware/response/soap_parser.rb', line 25

def log_error_details(env)
  Sentry.set_extras(url: env.url.to_s, body: env.body)
end

#on_complete(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/common/client/middleware/response/soap_parser.rb', line 8

def on_complete(env)
  case env.status
  when 200
    doc = parse_doc(env.body)
    if doc_includes_error?(doc)
      log_error_details(env)
      raise Common::Client::Errors::HTTPError.new('SOAP service returned internal server error', 500)
    end
    env.body = doc
  else
    log_error_details(env)
    raise Common::Client::Errors::HTTPError.new('SOAP HTTP call failed', env.status)
  end
end

#parse_doc(body) ⇒ Object (private)



29
30
31
# File 'lib/common/client/middleware/response/soap_parser.rb', line 29

def parse_doc(body)
  Ox.parse(ensure_xml_prolog(body))
end