Skip to content
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
5 changes: 5 additions & 0 deletions app/controllers/concerns/exception_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def log_error(error)
render :not_found, status: :not_found, locals: { exception: error }
end

rescue_from ActionController::ParameterMissing do |error|
log_error(error)
render :bad_request, status: :bad_request, locals: { exception: error }
end

rescue_from Error::PatronApiError do |error|
log_error(error)
render :patron_api_error, status: :service_unavailable
Expand Down
7 changes: 7 additions & 0 deletions app/views/application/bad_request.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>Bad Request</h1>

<p>Your browser sent a request that the server does not understand.</p>

<% if defined?(exception) && Rails.env.test? %>
<%= render(partial: 'exception_details', locals: { exception: exception }) %>
<% end %>
5 changes: 3 additions & 2 deletions spec/request/fees_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def base_url_for(user_id = nil)
allow(Rails.application.config).to receive(:alma_api_key).and_return(alma_api_key)
end

it 'throws a ParameterMissing error if request has no jwt' do
expect { get fees_path }.to raise_error(ActionController::ParameterMissing)
it 'shows a Bad Request error if request has no jwt' do
get fees_path
expect(response).to have_http_status(:bad_request)
end

it 'redirects to error page if request has a non-existant alma id' do
Expand Down
3 changes: 2 additions & 1 deletion spec/request/tind_download_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@

describe 'find_collection' do
it 'requires a collection' do
expect { get tind_download_find_collection_path }.to raise_error(ActionController::ParameterMissing)
get tind_download_find_collection_path
expect(response).to have_http_status :bad_request
end

it 'returns the matching collection name list' do
Expand Down
3 changes: 2 additions & 1 deletion spec/request/validate_proxy_patron_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def base_url_for(user_id)
end

it 'alerts user of invalid parameters' do
expect { post('/validate_proxy_patron') }.to raise_error ActionController::ParameterMissing
post('/validate_proxy_patron')
expect(response).to have_http_status :bad_request
end

it 'alerts user if they failed to authenticate' do
Expand Down