Commit c2e6bb8e authored by David Kim's avatar David Kim

Fallback to default project icon when Gitaly is not responding

parent a15388de
......@@ -122,6 +122,13 @@ module AvatarsHelper
else
source_identicon(source, options)
end
rescue GRPC::Unavailable, GRPC::DeadlineExceeded => e
# Handle Gitaly connection issues gracefully
Gitlab::ErrorTracking
.track_exception(e, source_type: source.class.name, source_id: source.id)
source_identicon(source, options)
end
def source_identicon(source, options = {})
......
......@@ -23,14 +23,43 @@ describe AvatarsHelper do
end
context 'when providing a project' do
it_behaves_like 'resource with a default avatar', 'project' do
let(:resource) { create(:project, name: 'foo') }
let(:helper_args) { [resource] }
end
let(:helper_args) { [resource] }
let(:resource) { create(:project, name: 'foo') }
it_behaves_like 'resource with a default avatar', 'project'
it_behaves_like 'resource with a custom avatar', 'project' do
let(:resource) { create(:project, :public, avatar: File.open(uploaded_image_temp_path)) }
let(:helper_args) { [resource] }
end
context 'when Gitaly is unavailable' do
before do
allow(resource).to receive(:avatar_url).and_raise(GRPC::Unavailable)
end
it 'handles Gitaly unavailable exceptions gracefully' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(GRPC::Unavailable), source_type: 'Project', source_id: resource.id
)
expect { project_icon(resource) }.not_to raise_error
end
it_behaves_like 'resource with a default avatar', 'project'
end
context 'when Gitaly request is taking too long' do
before do
allow(resource).to receive(:avatar_url).and_raise(GRPC::DeadlineExceeded)
end
it 'handles Gitaly timeout exceptions gracefully' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(GRPC::DeadlineExceeded), source_type: 'Project', source_id: resource.id
)
expect { project_icon(resource) }.not_to raise_error
end
it_behaves_like 'resource with a default avatar', 'project'
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