diff options
author | Seth Falcon <seth@opscode.com> | 2011-03-29 14:45:34 -0700 |
---|---|---|
committer | Seth Falcon <seth@opscode.com> | 2011-03-29 14:45:34 -0700 |
commit | 449006e419f5d8eff8c813d6a7921a18b005c95e (patch) | |
tree | 5c22316de51b9da77e997bd6f8323683ccfe271f /chef-server-api | |
parent | 15be833b130e3bc616da1cedb14a9d75d179c2d0 (diff) | |
download | chef-449006e419f5d8eff8c813d6a7921a18b005c95e.tar.gz |
[CHEF-2140] Rescue QueryParseError in search controller
Invalid queries are now caught and a 400 status is returned instead of
500.
Diffstat (limited to 'chef-server-api')
-rw-r--r-- | chef-server-api/app/controllers/search.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/chef-server-api/app/controllers/search.rb b/chef-server-api/app/controllers/search.rb index 1131c27034..77f83d0da0 100644 --- a/chef-server-api/app/controllers/search.rb +++ b/chef-server-api/app/controllers/search.rb @@ -41,6 +41,14 @@ class Search < Application end params[:type] = params.delete(:id) display(Chef::SolrQuery.from_params(params).search) + rescue Chef::Exceptions::QueryParseError => e + # we set status rather than raising BadRequest to avoid a + # stacktrace in the server log + self.status = 400 + e_msg = e.message.gsub(/\n/, " ") + msg = "invalid search query: '#{params[:q]}' #{e_msg}" + Chef::Log.warn("400 #{msg}") + display({ "error" => [msg] }) end def reindex |