Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default invalid_solr_id_error just a default 404 #766

Merged
merged 1 commit into from
Feb 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions lib/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,31 @@ def validate_email_params
flash[:error].blank?
end

# when a request for /catalog/BAD_SOLR_ID is made, this method is executed...
def invalid_solr_id_error
flash[:notice] = I18n.t('blacklight.search.errors.invalid_solr_id')
params.delete(:id)
index
render "index", :status => 404
# when a request for /catalog/BAD_SOLR_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_solr_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 }

# default to HTML response, even for other non-HTML formats we don't
# neccesarily know about, seems to be consistent with what Rails4 does
# by default with uncaught ActiveRecord::RecordNotFound in production
format.any do
# use standard, possibly locally overridden, 404.html file. Even for
# 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'
end
end
end

def start_new_search_session?
Expand Down
15 changes: 13 additions & 2 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,21 @@ def export_as_mock
controller.stub(:find => @mock_response,
:get_single_doc_via_search => @mock_document)
get :show, :id=>"987654321"
expect(request.flash[:notice]).to eq "Sorry, you have requested a record that doesn't exist."
expect(response).to render_template('index')
expect(response.status).to eq 404
expect(response.content_type).to eq Mime::HTML
end
it "should return status 404 for a record that doesn't exist even for non-html format" do
@mock_response = double()
@mock_response.stub(:docs => [])
@mock_document = double()
controller.stub(:find => @mock_response,
:get_single_doc_via_search => @mock_document)

get :show, :id=>"987654321", :format => "xml"
expect(response.status).to eq 404
expect(response.content_type).to eq Mime::XML
end

it "should redirect the user to the root url for a bad search" do
req = {}
res = {}
Expand Down
2 changes: 1 addition & 1 deletion spec/features/record_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
it "should not display 404" do
visit catalog_path('this_id_does_not_exist')
page.driver.status_code.should == 404
expect(page).to have_content "Sorry, you have requested a record that doesn't exist."
expect(page).to have_content "The page you were looking for doesn't exist."
end
end