Skip to content

Commit

Permalink
Merge pull request #1392 from alphagov/solr-400
Browse files Browse the repository at this point in the history
Show Not Found page for Solr 400 Bad Request errors
  • Loading branch information
AgaDufrat authored Jan 3, 2025
2 parents 3cb8eef + 2981f4b commit 2e16e50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/solr_dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def self.get_by_query(query:)
fl: Search::Solr.field_list,
}
rescue RSolr::Error::Http => e
if e.response[:status] == 404
if e.response[:status] == 404 || e.response[:status] == 400
raise NotFound
else
raise e
Expand Down
8 changes: 8 additions & 0 deletions spec/models/solr_dataset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
}.to raise_error(described_class::NotFound)
end

it "raises an exeption if Solr returns 400 response" do
mock_solr_http_error(status: 400)

expect {
described_class.get_by_uuid(uuid: "does-not-exist")
}.to raise_error(described_class::NotFound)
end

it "raises an exeption if Solr returns zero results" do
response = { "response" => {
"numFound" => 0,
Expand Down

0 comments on commit 2e16e50

Please sign in to comment.