Commit 962bb73a authored by Nick Thomas's avatar Nick Thomas

Merge branch 'sh-geo-handle-invalid-json-response' into 'master'

Geo: Gracefully handle a non-JSON response from the node status

See merge request gitlab-org/gitlab-ee!5685
parents 8000dcd9 39fffdff
...@@ -11,7 +11,11 @@ module Geo ...@@ -11,7 +11,11 @@ module Geo
data[:success] = response.success? data[:success] = response.success?
if response.success? if response.success?
data.merge!(response.parsed_response) if response.parsed_response.is_a?(Hash)
data.merge!(response.parsed_response)
else
data[:health] = 'A JSON response was not received'
end
else else
message = "Could not connect to Geo node - HTTP Status Code: #{response.code} #{response.message}" message = "Could not connect to Geo node - HTTP Status Code: #{response.code} #{response.message}"
payload = response.parsed_response payload = response.parsed_response
......
---
title: 'Geo: Gracefully handle a non-JSON response from the node status'
merge_request:
author:
type: fixed
...@@ -79,6 +79,18 @@ describe Geo::NodeStatusFetchService, :geo do ...@@ -79,6 +79,18 @@ describe Geo::NodeStatusFetchService, :geo do
expect(status.success).to be true expect(status.success).to be true
end end
it 'handles invalid JSON response' do
request = double(success?: true,
code: 200,
message: 'Something here',
parsed_response: 'Something here')
allow(Gitlab::HTTP).to receive(:get).and_return(request)
status = subject.call(secondary)
expect(status.status_message).to eq("A JSON response was not received")
end
it 'omits full response text in status' do it 'omits full response text in status' do
request = double(success?: false, request = double(success?: false,
code: 401, code: 401,
......
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