Skip to content

Commit

Permalink
Merge pull request #3873 from alphagov/add_guard_clause
Browse files Browse the repository at this point in the history
Add additional guard clause when we fetch popular tasks from SearchAPI
  • Loading branch information
hannako authored Nov 29, 2024
2 parents 6a47e1c + 778d4da commit 94c9bd7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/popular_list_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def search_response
fields: SearchApiFields::POPULAR_BROWSE_SEARCH_FIELDS,
}
Services.cached_search(params)
rescue GdsApi::HTTPServerError
{}
end

def second_level_browse_content_ids
Expand Down
7 changes: 7 additions & 0 deletions spec/models/popular_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,12 @@
stub_search(params:, body: search_response)
expect(popular_list.formatted_results).to eq expected_results
end

context "SearchAPI is unavailable" do
it "returns nil" do
stub_search_api_isnt_available
expect(popular_list.formatted_results).to eq nil
end
end
end
end
4 changes: 4 additions & 0 deletions spec/support/search_api_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module SearchApiHelpers
include SearchApiFields

def stub_search_api_isnt_available
stub_request(:any, /#{Plek.find('search-api')}\/.*/).to_return(status: 503)
end

def stub_search(body:, params: nil)
if params
stub_any_search
Expand Down

0 comments on commit 94c9bd7

Please sign in to comment.