6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/rets/parser/error_checker.rb', line 6
def self.check(response)
if response.respond_to?(:status_code) && response.status_code == 412
raise HttpError, "HTTP status: #{response.status_code}, body: #{response.body}"
end
if !response.body.empty?
begin
xml = Nokogiri::XML.parse(response.body, nil, nil, Nokogiri::XML::ParseOptions::STRICT)
rets_element = xml.xpath("/RETS")
unless rets_element.empty?
reply_text = (rets_element.attr("ReplyText") || rets_element.attr("replyText")).value
reply_code = (rets_element.attr("ReplyCode") || rets_element.attr("replyCode")).value.to_i
if reply_code == NoRecordsFound::ERROR_CODE
raise NoRecordsFound.new(reply_text)
elsif reply_code == NoObjectFound::ERROR_CODE
raise NoObjectFound.new(reply_text)
elsif reply_code.nonzero?
error_class = INVALID_REQUEST_ERROR_MAPPING[reply_code]
if error_class
raise error_class.new(reply_code, reply_text)
else
raise InvalidRequest.new(reply_code, reply_text)
end
else
return
end
end
rescue Nokogiri::XML::SyntaxError
end
end
if response.respond_to?(:ok?) && ! response.ok?
if response.status_code == 401
raise AuthorizationFailure.new(response.status_code, response.body)
else
raise HttpError, "HTTP status: #{response.status_code}, body: #{response.body}"
end
end
end
|