Commit 05ceec73 authored by Marc Shaw's avatar Marc Shaw

Merge branch 'graceful_degradation_for_refs' into 'master'

Graceful degradation for refs endpoint

See merge request gitlab-org/gitlab!83088
parents 54c4913e ebe9cdfc
...@@ -298,12 +298,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -298,12 +298,7 @@ class ProjectsController < Projects::ApplicationController
end end
if find_tags && @repository.tag_count.nonzero? if find_tags && @repository.tag_count.nonzero?
tags = begin tags = TagsFinder.new(@repository, refs_params).execute
TagsFinder.new(@repository, refs_params).execute
rescue Gitlab::Git::CommandError
[]
end
options['Tags'] = tags.take(100).map(&:name) options['Tags'] = tags.take(100).map(&:name)
end end
...@@ -314,6 +309,8 @@ class ProjectsController < Projects::ApplicationController ...@@ -314,6 +309,8 @@ class ProjectsController < Projects::ApplicationController
end end
render json: options.to_json render json: options.to_json
rescue Gitlab::Git::CommandError
render json: { error: _('Unable to load refs') }, status: :service_unavailable
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -39720,6 +39720,9 @@ msgstr "" ...@@ -39720,6 +39720,9 @@ msgstr ""
msgid "Unable to load file contents. Try again later." msgid "Unable to load file contents. Try again later."
msgstr "" msgstr ""
msgid "Unable to load refs"
msgstr ""
msgid "Unable to load the diff" msgid "Unable to load the diff"
msgstr "" msgstr ""
......
...@@ -1137,16 +1137,15 @@ RSpec.describe ProjectsController do ...@@ -1137,16 +1137,15 @@ RSpec.describe ProjectsController do
context 'when gitaly is unavailable' do context 'when gitaly is unavailable' do
before do before do
expect_next_instance_of(TagsFinder) do |finder| 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
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" } get :refs, params: { namespace_id: project.namespace, id: project, ref: "123456" }
expect(json_response["Branches"]).to include("master") expect(response).to have_gitlab_http_status(:service_unavailable)
expect(json_response["Tags"]).to eq([]) expect(json_response['error']).to eq 'Unable to load refs'
expect(json_response["Commits"]).to include("123456")
end end
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