I am trying to make it so that an ActionController::UnknownFormat
will not raise an exception report in production. I'm using Rails 4 and thought something like this would do the trick, but it doesn't seem to make a difference:
application.rb
config.action_dispatch.rescue_responses.merge!('ActionController::UnknownFormat' => :not_found)
It looks like this was deprecated in Rails 4 in favor of this rescue_from
syntax. So something like this:
application_controller.rb:
rescue_from ActionController::UnknownFormat, with: :raise_not_found
def raise_not_found
render(text: 'Not Found', status: 404)
end
It should not return status code 404, should return status code 415 i.e unsupported_media_type
rescue_from ActionController::UnknownFormat, with: :raise_not_found
def raise_not_found
render(text: 'Not Found', status: :unsupported_media_type)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With