summaryrefslogtreecommitdiff
path: root/lib/chef_zero/solr/solr_parser.rb
diff options
context:
space:
mode:
authorSteven Danna <steve@opscode.com>2014-11-15 18:50:58 +0000
committerLamont Granquist <lamont@scriptkiddie.org>2016-07-19 10:14:11 -0700
commitf310cc0f92158f3e5f83193a88203636404c8e0d (patch)
treebedd55f171a4455cb6a28beada5d3f6d521c3ee1 /lib/chef_zero/solr/solr_parser.rb
parentdc14c7f2c362b538b85dff3c5f0f5451d100da62 (diff)
downloadchef-zero-lcg/rebase-101.tar.gz
Return HTTP 400 Bad Request on Solr parse errorlcg/rebase-101
Previously, chef-zero would return an HTTP 500 Internal Server Error when the Solr parser failed. Now, we return HTTP 400 with an error message identical to that of the Erchef server. Returning HTTP 400 also improves the end-user experience since knife returns more sensible error messages. Before this patch: > knife search nodes 'recipes:bar::bar' ERROR: Server returned error 500 for http://127.0.0.1:8889/search... After: > knife search nodes 'recipes:bar::bar' ERROR: knife search failed: invalid search query: 'recipes:bar::bar'
Diffstat (limited to 'lib/chef_zero/solr/solr_parser.rb')
-rw-r--r--lib/chef_zero/solr/solr_parser.rb4
1 files changed, 3 insertions, 1 deletions
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