]> cat aescling's git repositories - mastodon.git/commitdiff
Catch ActionController::UnknownFormat and return HTTP 406 (#7621)
authorEugen Rochko <eugen@zeonfederated.com>
Fri, 25 May 2018 23:09:30 +0000 (01:09 +0200)
committerGitHub <noreply@github.com>
Fri, 25 May 2018 23:09:30 +0000 (01:09 +0200)
An error like that should not appear in production error log.

app/controllers/application_controller.rb

index 5b22f17c63e666430ae3e8dc10754b518e19e18f..29ba6cad616b1a5902fcd2f61e3510dfef00a04b 100644 (file)
@@ -20,6 +20,7 @@ class ApplicationController < ActionController::Base
   rescue_from ActionController::RoutingError, with: :not_found
   rescue_from ActiveRecord::RecordNotFound, with: :not_found
   rescue_from ActionController::InvalidAuthenticityToken, with: :unprocessable_entity
+  rescue_from ActionController::UnknownFormat, with: :not_acceptable
   rescue_from Mastodon::NotPermittedError, with: :forbidden
 
   before_action :store_current_location, except: :raise_not_found, unless: :devise_controller?
@@ -73,6 +74,10 @@ class ApplicationController < ActionController::Base
     respond_with_error(422)
   end
 
+  def not_acceptable
+    respond_with_error(406)
+  end
+
   def single_user_mode?
     @single_user_mode ||= Rails.configuration.x.single_user_mode && Account.exists?
   end