Skip to content

Commit

Permalink
Merge pull request #1050 from alphagov/suppress-rummager-errors
Browse files Browse the repository at this point in the history
Catch rummager errors for navigation
  • Loading branch information
oscarwyatt authored Aug 15, 2018
2 parents f9c478a + 29f4011 commit 8701768
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/lib/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.content_store
end

def self.rummager
@rummager ||= GdsApi::Rummager.new(Plek.new.find("rummager"))
@rummager ||= GdsApi::Rummager.new(Plek.new.find("rummager"),
timeout: 2)
end
end
3 changes: 3 additions & 0 deletions app/services/most_popular_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def self.fetch(content_ids:, current_path:, filters:)

def fetch
search_response["results"]
rescue GdsApi::HTTPErrorResponse => e
GovukStatsd.increment("govuk_content_pages.most_popular.#{e.class.name.demodulize.downcase}")
[]
end

private
Expand Down
3 changes: 3 additions & 0 deletions app/services/most_recent_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def self.fetch(content_ids:, current_path:, filters:)

def fetch
search_response["results"]
rescue GdsApi::HTTPErrorResponse => e
GovukStatsd.increment("govuk_content_pages.most_recent.#{e.class.name.demodulize.downcase}")
[]
end

private
Expand Down
7 changes: 7 additions & 0 deletions test/services/most_popular_content_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def taxon_content_ids
assert_equal(results.count, 2)
end

test 'catches api errors' do
Services.rummager.stubs(:search).raises(GdsApi::HTTPErrorResponse.new(500))
results = most_popular_content.fetch

assert_equal(results, [])
end

test 'starts from the first page' do
assert_includes_params(start: 0) do
most_popular_content.fetch
Expand Down
7 changes: 7 additions & 0 deletions test/services/most_recent_content_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def most_recent_content
)
end

test 'catches api errors' do
Services.rummager.stubs(:search).raises(GdsApi::HTTPErrorResponse.new(500))
results = most_recent_content.fetch

assert_equal(results, [])
end

def taxon_content_ids
['c3c860fc-a271-4114-b512-1c48c0f82564', 'ff0e8e1f-4dea-42ff-b1d5-f1ae37807af2']
end
Expand Down

0 comments on commit 8701768

Please sign in to comment.