rescue ES BadRequest errors, record in Datadog, and return an empty array (#6219) [deploy]

This commit is contained in:
Molly Struve 2020-02-20 18:04:19 -05:00 committed by GitHub
parent dfbc1b3791
commit 18d9bf1de7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View file

@ -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

View file

@ -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