Commit 0e90284c authored by Pawel Chojnacki's avatar Pawel Chojnacki

Catch json parsing error as PrometheusError

parent 5209689d
......@@ -42,6 +42,8 @@ module Gitlab
def json_api_get(type, args = {})
path = ['api', 'v1', type].join('/')
get(path, args)
rescue JSON::ParserError
raise PrometheusError, 'Parsing response failed'
rescue Errno::ECONNREFUSED
raise PrometheusError, 'Connection refused'
end
......
......@@ -47,6 +47,16 @@ describe Gitlab::PrometheusClient do
expect(req_stub).to have_been_requested
end
end
context 'when request returns non json data' do
it 'raises a Gitlab::PrometheusError error' do
req_stub = stub_prometheus_request(query_url, status: 200, body: 'not json')
expect { execute_query }
.to raise_error(Gitlab::PrometheusError, 'Parsing response failed')
expect(req_stub).to have_been_requested
end
end
end
describe 'failure to reach a provided prometheus url' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment