Skip to content

Commit

Permalink
Move exception handling code from invalid_solr_id_error to invalid_do…
Browse files Browse the repository at this point in the history
…cument_id_error
  • Loading branch information
jcoyne committed Feb 19, 2015
1 parent 45eb82c commit c0d381f
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions lib/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,29 +297,19 @@ def validate_email_params
end

##
# when a request for /catalog/BAD_SOLR_ID is made, this method is executed.
# when a request for /catalog/BAD_ID is made, this method is executed.
# Just returns a 404 response, but you can override locally in your own
# CatalogController to do something else -- older BL displayed a Catalog#inde
# page with a flash message and a 404 status.
def invalid_document_id_error *args
Deprecation.silence(Blacklight::Catalog) do
invalid_solr_id_error *args
end
end

##
# DEPRECATED; this method will be removed in Blacklight 6.0 and the functionality
# moved to invalid_document_id_error
def invalid_solr_id_error(exception)
Deprecation.warn Blacklight::Catalog, "#invalid_solr_id_error is deprecated; used #invalid_document_id_error instead"
def invalid_document_id_error exception
error_info = {
"status" => "404",
"error" => "#{exception.class}: #{exception.message}"
}

respond_to do |format|
format.xml { render :xml => error_info, :status => 404 }
format.json { render :json => error_info, :status => 404 }
format.xml { render xml: error_info, status: 404 }
format.json { render json: error_info, status: 404 }

# default to HTML response, even for other non-HTML formats we don't
# neccesarily know about, seems to be consistent with what Rails4 does
Expand All @@ -329,11 +319,19 @@ def invalid_solr_id_error(exception)
# possibly non-html formats, this is consistent with what Rails does
# on raising an ActiveRecord::RecordNotFound. Rails.root IS needed
# for it to work under testing, without worrying about CWD.
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false, :content_type => 'text/html'
render file: "#{Rails.root}/public/404.html", status: 404, layout: false, content_type: 'text/html'
end
end
end

##
# DEPRECATED; this method will be removed in Blacklight 6.0 and the functionality
# moved to invalid_document_id_error
def invalid_solr_id_error(exception)
Deprecation.warn Blacklight::Catalog, "#invalid_solr_id_error is deprecated; used #invalid_document_id_error instead"
invalid_document_id_error exception
end

def start_new_search_session?
action_name == "index"
end
Expand Down

0 comments on commit c0d381f

Please sign in to comment.