Commit 812754d1 authored by Stan Hu's avatar Stan Hu

Return 404 instead of a 500 error on API status endpoint if Geo tracking DB is not enabled

If the tracking database is not configured, the secondary attempts to read from
the Geo DB but fails spectacularly because the tables don't exist.
parent 42c9bde5
---
title: Return 404 instead of a 500 error on API status endpoint if Geo tracking DB is not enabled
merge_request:
author:
...@@ -35,6 +35,7 @@ module API ...@@ -35,6 +35,7 @@ module API
get 'status' do get 'status' do
authenticate_by_gitlab_geo_node_token! authenticate_by_gitlab_geo_node_token!
require_node_to_be_secondary! require_node_to_be_secondary!
require_node_to_have_tracking_db!
present GeoNodeStatus.new, with: Entities::GeoNodeStatus present GeoNodeStatus.new, with: Entities::GeoNodeStatus
end end
...@@ -105,6 +106,10 @@ module API ...@@ -105,6 +106,10 @@ module API
def require_node_to_be_secondary! def require_node_to_be_secondary!
forbidden! 'Geo node is not secondary node.' unless Gitlab::Geo.current_node&.secondary? forbidden! 'Geo node is not secondary node.' unless Gitlab::Geo.current_node&.secondary?
end end
def require_node_to_have_tracking_db!
not_found! 'Geo node does not have its tracking database enabled.' unless Gitlab::Geo.configured?
end
end end
end end
end end
...@@ -180,6 +180,14 @@ describe API::Geo, api: true do ...@@ -180,6 +180,14 @@ describe API::Geo, api: true do
expect(response.status).to eq 200 expect(response.status).to eq 200
expect(response.headers['Content-Type']).to eq('application/json') expect(response.headers['Content-Type']).to eq('application/json')
end end
it 'responds with a 404 when the tracking database is disabled' do
allow(Gitlab::Geo).to receive(:configured?).and_return(false)
get api('/geo/status'), nil, request.headers
expect(response).to have_http_status(404)
end
end end
context 'when requesting primary node with valid auth header' do context 'when requesting primary node with valid auth header' 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