Skip to content
Browse files

Make ActionDispatch::ParamsParser::ParseError#original_exception retu…

…rn the original exception.
  • Loading branch information...
1 parent b6ba012 commit fd99bb892652b1ffffdd7f9271184235d6040111 @szimek szimek committed Aug 27, 2012
View
14 actionpack/lib/action_dispatch/middleware/params_parser.rb
@@ -4,7 +4,14 @@
module ActionDispatch
class ParamsParser
- class ParseError < StandardError; end
+ class ParseError < StandardError
+ attr_reader :original_exception
+
+ def initialize(message, original_exception)
+ super(message)
+ @original_exception = original_exception
+ end
+ end
DEFAULT_PARSERS = {
Mime::XML => :xml_simple,
@@ -52,10 +59,9 @@ def parse_formatted_parameters(env)
false
end
rescue Exception => e # YAML, XML or Ruby code block errors
- message = "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"
- logger(env).debug message
+ logger(env).debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"
- raise ParseError, message
+ raise ParseError.new(e.message, e)
end
def content_type_from_legacy_post_data_format_header(env)
View
3 actionpack/test/dispatch/request/json_params_parsing_test.rb
@@ -47,7 +47,8 @@ def teardown
$stderr = StringIO.new # suppress the log
json = "[\"person]\": {\"name\": \"David\"}}"
exception = assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => false} }
- assert_match json, exception.message
+ assert_equal MultiJson::DecodeError, exception.original_exception.class
+ assert_equal exception.original_exception.message, exception.message
ensure
$stderr = STDERR
end
View
3 actionpack/test/dispatch/request/xml_params_parsing_test.rb
@@ -69,7 +69,8 @@ def call(env)
$stderr = StringIO.new # suppress the log
xml = "<person><name>David</name></pineapple>"
exception = assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => false) }
- assert_match xml, exception.message
+ assert_equal REXML::ParseException, exception.original_exception.class
+ assert_equal exception.original_exception.message, exception.message
ensure
$stderr = STDERR
end

0 comments on commit fd99bb8

Please sign in to comment.
Something went wrong with that request. Please try again.