summaryrefslogtreecommitdiff
path: root/lib/gitlab/prometheus_client.rb
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2018-01-04 03:13:54 +0100
committerPawel Chojnacki <pawel@chojnacki.ws>2018-01-04 03:13:54 +0100
commit9c0b10da4147470050c1ae144fc75c2963eeb4ba (patch)
treec098f87759f5171bfccf34dda24842dc5830b566 /lib/gitlab/prometheus_client.rb
parent80d4c0675f5715d724be20d47cafa372524e3ed1 (diff)
downloadgitlab-ce-9c0b10da4147470050c1ae144fc75c2963eeb4ba.tar.gz
Fix prometheus client tests
Diffstat (limited to 'lib/gitlab/prometheus_client.rb')
-rw-r--r--lib/gitlab/prometheus_client.rb17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/gitlab/prometheus_client.rb b/lib/gitlab/prometheus_client.rb
index d1875dd1042..79f66b42c21 100644
--- a/lib/gitlab/prometheus_client.rb
+++ b/lib/gitlab/prometheus_client.rb
@@ -50,10 +50,12 @@ module Gitlab
response = rest_client[path].get(params: args)
handle_response(response)
rescue SocketError
- raise PrometheusError, "Can't connect to #{url}"
+ raise PrometheusError, "Can't connect to #{rest_client.url}"
rescue OpenSSL::SSL::SSLError
- raise PrometheusError, "#{url} contains invalid SSL data"
- rescue HTTParty::Error
+ raise PrometheusError, "#{rest_client.url} contains invalid SSL data"
+ rescue RestClient::ExceptionWithResponse => ex
+ handle_exception_response(ex.response)
+ rescue RestClient::Exception
raise PrometheusError, "Network connection error"
end
@@ -61,7 +63,14 @@ module Gitlab
json_data = JSON.parse(response.body)
if response.code == 200 && json_data['status'] == 'success'
json_data['data'] || {}
- elsif response.code == 400
+ else
+ raise PrometheusError, "#{response.code} - #{response.body}"
+ end
+ end
+
+ def handle_exception_response(response)
+ if response.code == 400
+ json_data = JSON.parse(response.body)
raise PrometheusError, json_data['error'] || 'Bad data received'
else
raise PrometheusError, "#{response.code} - #{response.body}"