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 = {})
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue