Commit ebe9cdfc authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Graceful degradation for refs endpoint

**Problem**

We have an unhandled exception when Gitaly is not available.

**Solution**

Return 503 error with an error message.

Changelog: added
parent 39da3930
......@@ -305,12 +305,7 @@ class ProjectsController < Projects::ApplicationController
end
if find_tags && @repository.tag_count.nonzero?
tags = begin
TagsFinder.new(@repository, refs_params).execute
rescue Gitlab::Git::CommandError
[]
end
tags = TagsFinder.new(@repository, refs_params).execute
options['Tags'] = tags.take(100).map(&:name)
end
......@@ -321,6 +316,8 @@ class ProjectsController < Projects::ApplicationController
end
render json: options.to_json
rescue Gitlab::Git::CommandError
render json: { error: _('Unable to load refs') }, status: :service_unavailable
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -39636,6 +39636,9 @@ msgstr ""
msgid "Unable to load file contents. Try again later."
msgstr ""
msgid "Unable to load refs"
msgstr ""
msgid "Unable to load the diff"
msgstr ""
......
......@@ -1159,16 +1159,15 @@ RSpec.describe ProjectsController do
context 'when gitaly is unavailable' do
before do
expect_next_instance_of(TagsFinder) do |finder|
allow(finder).to receive(:execute).and_raise(Gitlab::Git::CommandError)
allow(finder).to receive(:execute).and_raise(Gitlab::Git::CommandError, 'something went wrong')
end
end
it 'gets an empty list of tags' do
it 'responds with 503 error' do
get :refs, params: { namespace_id: project.namespace, id: project, ref: "123456" }
expect(json_response["Branches"]).to include("master")
expect(json_response["Tags"]).to eq([])
expect(json_response["Commits"]).to include("123456")
expect(response).to have_gitlab_http_status(:service_unavailable)
expect(json_response['error']).to eq 'Unable to load refs'
end
end
......
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