diff options
-rw-r--r-- | lib/chef_zero/endpoints/search_endpoint.rb | 10 | ||||
-rw-r--r-- | lib/chef_zero/solr/solr_parser.rb | 4 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/chef_zero/endpoints/search_endpoint.rb b/lib/chef_zero/endpoints/search_endpoint.rb index a9ad2bf..63d7f4a 100644 --- a/lib/chef_zero/endpoints/search_endpoint.rb +++ b/lib/chef_zero/endpoints/search_endpoint.rb @@ -14,6 +14,8 @@ module ChefZero results = search(request, orgname) results['rows'] = results['rows'].map { |name,uri,value,search_value| value } json_response(200, results) + rescue ChefZero::Solr::ParseError + bad_search_request(request) end def post(request) @@ -43,10 +45,18 @@ module ChefZero 'start' => full_results['start'], 'total' => full_results['total'] }) + rescue ChefZero::Solr::ParseError + bad_search_request(request) end private + def bad_search_request(request) + query_string = request.query_params['q'] + resp = {"error" => ["invalid search query: '#{query_string}'"]} + json_response(400, resp) + end + def search_container(request, index, orgname) relative_parts, normalize_proc = case index when 'client' diff --git a/lib/chef_zero/solr/solr_parser.rb b/lib/chef_zero/solr/solr_parser.rb index 936ead1..99da5fe 100644 --- a/lib/chef_zero/solr/solr_parser.rb +++ b/lib/chef_zero/solr/solr_parser.rb @@ -7,6 +7,8 @@ require 'chef_zero/solr/query/subquery' module ChefZero module Solr + class ParseError < RuntimeError; end + class SolrParser def initialize(query_string) @query_string = query_string @@ -114,7 +116,7 @@ module ChefZero end def parse_error(token, str) - raise "Error on token '#{token}' at #{@index} of '#{@query_string}': #{str}" + raise ChefZero::Solr::ParseError, "Error on token '#{token}' at #{@index} of '#{@query_string}': #{str}" end def read_single_expression |