How to deal with "invalid %-encoding" error in application for malformed uri

I would suggest to just ignore this error in your exception notifier instead.

Lead by a discussion Show archive.org snapshot of this issue, I built in a middleware which answers those requests with [400] bad request rather than raising an ArgumentError.

I put it into app/util and configured application.rb like that:

# catches 'invalid %-encoding' error
require "#{Rails.root}/app/util/exception_app"
config.middleware.insert_before Rack::Runtime, ExceptionApp::Middleware

Note: Rails 4.2+ raises an ActionController::BadRequest error instead of an ArgumentError.

Over 8 years ago