Last active
August 29, 2015 13:56
-
-
Save printercu/9226096 to your computer and use it in GitHub Desktop.
rails 3.2: 400 for malformed request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/action_dispatch_params_parser.rb | |
# backport from 4.0 | |
module ActionDispatch | |
class ParamsParser | |
class ParseError < StandardError | |
attr_reader :original_exception | |
def initialize(message, original_exception) | |
super(message) | |
@original_exception = original_exception | |
end | |
end | |
private | |
def parse_formatted_parameters_with_rescue(env) | |
parse_formatted_parameters_without_rescue(env) | |
rescue Exception => e | |
raise ParseError.new(e.message, e) | |
end | |
alias_method_chain :parse_formatted_parameters, :rescue | |
end | |
end | |
ActionDispatch::ExceptionWrapper.rescue_responses.merge!( | |
'ActionDispatch::ParamsParser::ParseError' => :bad_request, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment