diff --git a/app/helpers/hyrax/hyrax_helper_behavior.rb b/app/helpers/hyrax/hyrax_helper_behavior.rb index b7d75bc479..bd1d6030df 100644 --- a/app/helpers/hyrax/hyrax_helper_behavior.rb +++ b/app/helpers/hyrax/hyrax_helper_behavior.rb @@ -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 ## diff --git a/spec/helpers/hyrax_helper_spec.rb b/spec/helpers/hyrax_helper_spec.rb index 7da72981ab..377693469a 100644 --- a/spec/helpers/hyrax_helper_spec.rb +++ b/spec/helpers/hyrax_helper_spec.rb @@ -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 @@ -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