Catch json parsing error as PrometheusError
This commit is contained in:
parent
5209689d95
commit
0e90284c11
|
@ -42,6 +42,8 @@ module Gitlab
|
||||||
def json_api_get(type, args = {})
|
def json_api_get(type, args = {})
|
||||||
path = ['api', 'v1', type].join('/')
|
path = ['api', 'v1', type].join('/')
|
||||||
get(path, args)
|
get(path, args)
|
||||||
|
rescue JSON::ParserError
|
||||||
|
raise PrometheusError, 'Parsing response failed'
|
||||||
rescue Errno::ECONNREFUSED
|
rescue Errno::ECONNREFUSED
|
||||||
raise PrometheusError, 'Connection refused'
|
raise PrometheusError, 'Connection refused'
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,6 +47,16 @@ describe Gitlab::PrometheusClient do
|
||||||
expect(req_stub).to have_been_requested
|
expect(req_stub).to have_been_requested
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
describe 'failure to reach a provided prometheus url' do
|
describe 'failure to reach a provided prometheus url' do
|
||||||
|
|
Loading…
Reference in New Issue