Skip to content

Commit

Permalink
Merge pull request #14024 from krauselukas/fix/issue_14007
Browse files Browse the repository at this point in the history
Rescue from Backend::Error in Project::KeyInfo
  • Loading branch information
krauselukas committed Mar 16, 2023
2 parents 79f5d15 + 17f3666 commit 91173f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/api/app/models/project/key_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class KeyInfo

def self.find_by_project(project)
response = key_info_for_project(project)
return if response.blank?

parsed_response = Xmlhash.parse(response)

Expand All @@ -40,6 +41,8 @@ def self.find_by_project(project)
def self.key_info_for_project(project)
Rails.cache.fetch("key_info_project_#{project.cache_key_with_version}", expires_in: CACHE_EXPIRY_TIME) do
Backend::Api::Sources::Project.key_info(project.name)
rescue Backend::Error
{}
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions src/api/spec/models/project/key_info_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rails_helper'

RSpec.describe Project::KeyInfo do
describe '#find_by_project' do
context 'when the backend throws an error' do
let(:project) { create(:project, name: 'foo') }

before do
allow(Backend::Api::Sources::Project).to receive(:key_info).and_raise(Backend::Error)
end

it 'rescues from the error and returns nil' do
expect(described_class.find_by_project(project)).to be_nil
end
end
end
end

0 comments on commit 91173f6

Please sign in to comment.