Skip to content

Commit

Permalink
raise special exception for invalid search term
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaltom committed Dec 19, 2012
1 parent 179c4b2 commit 2f03ac4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ class MissingParameterError < Exception; end

rescue_from Exception do |exception|
logger.error "Exception: #{exception.class}: #{exception.message}"
logger.error exception.backtrace.join("\n")
@message = exception.message
layout = request.xhr? ? false : "application"
notify_hoptoad(exception)
case exception
when Seeker::InvalidSearchTerm
else
logger.error exception.backtrace.join("\n")
notify_hoptoad(exception)
end
render :template => 'error', :formats => [:html], :layout => layout, :status => 400
end

Expand Down
3 changes: 2 additions & 1 deletion app/models/seeker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ def self.prepare_result(query, baseproject=nil, project=nil, exclude_filter=nil,
end
end

class InvalidSearchTerm < Exception; end

class SearchResult < Array
def self.search(query, baseproject, project=nil, exclude_filter=nil, exclude_debug=false)
words = query.split(" ").select {|part| !part.match(/^[0-9_\.-]+$/) }
versrel = query.split(" ").select {|part| part.match(/^[0-9_\.-]+$/) }
logger.debug "splitted words and versrel: #{words.inspect} #{versrel.inspect}"
raise "Please provide a valid search term" if words.blank? && project.blank?
raise InvalidSearchTerm.new "Please provide a valid search term" if words.blank? && project.blank?

xpath_items = Array.new
xpath_items << "@project = '#{project}' " unless project.blank?
Expand Down

0 comments on commit 2f03ac4

Please sign in to comment.