rescue ES BadRequest errors, record in Datadog, and return an empty array (#6219) [deploy]
This commit is contained in:
parent
dfbc1b3791
commit
18d9bf1de7
2 changed files with 10 additions and 0 deletions
|
|
@ -5,5 +5,8 @@ class SearchController < ApplicationController
|
|||
tag_docs = Search::Tag.search_documents("name:#{params[:name]}* AND supported:true")
|
||||
|
||||
render json: { result: tag_docs }
|
||||
rescue Elasticsearch::Transport::Transport::Errors::BadRequest
|
||||
DataDogStatsClient.increment("elasticsearch.errors", tags: ["error:BadRequest"])
|
||||
render json: { result: [] }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,5 +15,12 @@ RSpec.describe "Search", type: :request, proper_status: true do
|
|||
get "/search/tags"
|
||||
expect(response.parsed_body).to eq("result" => mock_documents)
|
||||
end
|
||||
|
||||
it "returns an empty array when a Elasticsearch Bad Request error is raised" do
|
||||
sign_in authorized_user
|
||||
allow(Search::Tag).to receive(:search_documents).and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest)
|
||||
get "/search/tags"
|
||||
expect(response.parsed_body).to eq("result" => [])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue