Skip to content

Instantly share code, notes, and snippets.

@printercu
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save printercu/9226096 to your computer and use it in GitHub Desktop.
Save printercu/9226096 to your computer and use it in GitHub Desktop.
rails 3.2: 400 for malformed request
# 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