blob: 38175d5687afe62bf4be75009809b913040c53d7 (
plain)
1
2
3
4
5
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
|
# frozen_string_literal: true
module QA
module Vendor
module Jenkins
module Helpers
private
def try_parse(string)
JSON.parse(string)
rescue StandardError => _e
nil
end
def check_network_error(response)
raise NetworkError, "#{response.code} - #{response.body}" if response.code >= 400
end
def handle_json_response(response)
check_network_error(response)
set_cookies(response)
unless (data = try_parse(response.body))
raise NotParseableError, "Code: #{response.code}\nBody: #{response.body}"
end
data
end
def set_cookies(response)
self.cookies = response.cookies
end
end
end
end
end
|