]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/application_controller.rb
Merge pull request #4680 from tomhughes/validate-page-numbers
[rails.git] / app / controllers / application_controller.rb
index 5d69a5fc8c1fb54c16f7b382b059096bce4122ad..f5accc3c44d2d65654105a828d5ccc0fc6e94b64 100644 (file)
@@ -10,6 +10,8 @@ class ApplicationController < ActionController::Base
   rescue_from CanCan::AccessDenied, :with => :deny_access
   check_authorization
 
+  rescue_from RailsParam::InvalidParameterError, :with => :invalid_parameter
+
   before_action :fetch_body
   around_action :better_errors_allow_inline, :if => proc { Rails.env.development? }
 
@@ -310,6 +312,17 @@ class ApplicationController < ActionController::Base
     end
   end
 
+  def invalid_parameter(_exception)
+    if request.get?
+      respond_to do |format|
+        format.html { redirect_to :controller => "/errors", :action => "bad_request" }
+        format.any { head :bad_request }
+      end
+    else
+      head :bad_request
+    end
+  end
+
   # extract authorisation credentials from headers, returns user = nil if none
   def auth_data
     if request.env.key? "X-HTTP_AUTHORIZATION" # where mod_rewrite might have put it