Skip to content

Commit 3f665ff

Browse files
committed
app: Add ParameterMissing exception handling
This way, if a parameter is missing in a request, it is logged as a 400 Bad Request instead of a 500 Internal Server Error.
1 parent 2e73735 commit 3f665ff

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

app/controllers/concerns/exception_handling.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ def log_error(error)
2929
render :not_found, status: :not_found, locals: { exception: error }
3030
end
3131

32+
rescue_from ActionController::ParameterMissing do |error|
33+
log_error(error)
34+
render :bad_request, status: :bad_request, locals: { exception: error }
35+
end
36+
3237
rescue_from Error::PatronApiError do |error|
3338
log_error(error)
3439
render :patron_api_error, status: :service_unavailable
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h1>Bad Request</h1>
2+
3+
<p>Your browser sent a request that the server does not understand.</p>
4+
5+
<% if defined?(exception) && Rails.env.test? %>
6+
<%= render(partial: 'exception_details', locals: { exception: exception }) %>
7+
<% end %>

0 commit comments

Comments
 (0)