Skip to content

Commit

Permalink
Rescue exception when collection is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
dlpierce authored and jeremyf committed Feb 2, 2024
1 parent 653cb61 commit fdcabe6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/helpers/hyrax/hyrax_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ def collection_title_by_id(id)
solr_field = solr_docs.first["title_tesim"]
return nil if solr_field.nil?
solr_field.first
rescue Blacklight::Exceptions::RecordNotFound
nil
end

##
Expand Down
5 changes: 5 additions & 0 deletions spec/helpers/hyrax_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ def new_state
allow(repository).to receive(:find).with("abcd12345").and_return(solr_response)
allow(repository).to receive(:find).with("efgh67890").and_return(bad_solr_response)
allow(repository).to receive(:find).with("bad-id").and_return(empty_solr_response)
allow(repository).to receive(:find).with("error-id").and_raise(Blacklight::Exceptions::RecordNotFound)
end

it "returns the first title of the collection" do
Expand All @@ -388,6 +389,10 @@ def new_state
it "returns nil if collection not found" do
expect(helper.collection_title_by_id("bad-id")).to eq nil
end

it "returns nil if RecordNotFound is raised" do
expect(helper.collection_title_by_id("error-id")).to eq nil
end
end

describe "#thumbnail_label_for" do
Expand Down

0 comments on commit fdcabe6

Please sign in to comment.