aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2016-06-19 21:09:41 -0400
committerRafael Mendonça França <rafaelmfranca@gmail.com>2016-10-10 01:35:58 -0300
commitb3d41eae4b138d6c9d38bd9c1cbe033802c0e21d (patch)
treeeb7514a733481a43f0f1ddc125f88bcbe76f9dfe
parent53d2b7335af0fc14c3522cbceb54c0f28d35c3e0 (diff)
downloadrails-b3d41eae4b138d6c9d38bd9c1cbe033802c0e21d.tar.gz
rails-b3d41eae4b138d6c9d38bd9c1cbe033802c0e21d.tar.bz2
rails-b3d41eae4b138d6c9d38bd9c1cbe033802c0e21d.zip
Deprecated ActionDispatch::ParamsParser::ParamsParser
ActionDispatch::ParamsParser class was removed in favor of ActionDispatch::Http::Parameters so it is better to move the error constant to the new class.
-rw-r--r--actionpack/CHANGELOG.md5
-rw-r--r--actionpack/lib/action_dispatch.rb1
-rw-r--r--actionpack/lib/action_dispatch/http/parameters.rb14
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb2
-rw-r--r--actionpack/lib/action_dispatch/middleware/exception_wrapper.rb26
-rw-r--r--actionpack/lib/action_dispatch/middleware/params_parser.rb18
-rw-r--r--actionpack/test/dispatch/request/json_params_parsing_test.rb2
-rw-r--r--actionpack/test/dispatch/show_exceptions_test.rb2
-rw-r--r--guides/source/configuring.md34
9 files changed, 51 insertions, 53 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index e4df059369..d6652eaf9f 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Deprecate `ActionDispatch::ParamsParser::ParseError` in favor of
+ `ActionDispatch::Http::Parameters::ParseError`.
+
+ *Rafael Mendonça França*
+
* Remove deprecated `ActionDispatch::ParamsParser`.
*Rafael Mendonça França*
diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb
index 60cee6acbd..7931e53c3e 100644
--- a/actionpack/lib/action_dispatch.rb
+++ b/actionpack/lib/action_dispatch.rb
@@ -54,7 +54,6 @@ module ActionDispatch
autoload :ExceptionWrapper
autoload :Executor
autoload :Flash
- autoload :ParamsParser
autoload :PublicExceptions
autoload :Reloader
autoload :RemoteIp
diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb
index 31ef0af791..ddd15b748b 100644
--- a/actionpack/lib/action_dispatch/http/parameters.rb
+++ b/actionpack/lib/action_dispatch/http/parameters.rb
@@ -12,6 +12,14 @@ module ActionDispatch
}
}
+ # Raised when raw data from the request cannot be parsed by the parser
+ # defined for request's content mime type.
+ class ParseError < StandardError
+ def initialize
+ super($!.message)
+ end
+ end
+
included do
class << self
attr_reader :parameter_parsers
@@ -91,7 +99,7 @@ module ActionDispatch
my_logger = logger || ActiveSupport::Logger.new($stderr)
my_logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{raw_post}"
- raise ParamsParser::ParseError
+ raise ParseError
end
end
@@ -100,4 +108,8 @@ module ActionDispatch
end
end
end
+
+ module ParamsParser
+ ParseError = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("ActionDispatch::ParamsParser::ParseError", "ActionDispatch::Http::Parameters::ParseError")
+ end
end
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index e4ef9783f3..9986d6e1e9 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -357,7 +357,7 @@ module ActionDispatch
end
self.request_parameters = Request::Utils.normalize_encode_params(pr)
end
- rescue ParamsParser::ParseError # one of the parse strategies blew up
+ rescue Http::Parameters::ParseError # one of the parse strategies blew up
self.request_parameters = Request::Utils.normalize_encode_params(super || {})
raise
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
diff --git a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
index 9b44c4483e..99dc37c568 100644
--- a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
+++ b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
@@ -6,19 +6,19 @@ module ActionDispatch
cattr_accessor :rescue_responses
@@rescue_responses = Hash.new(:internal_server_error)
@@rescue_responses.merge!(
- "ActionController::RoutingError" => :not_found,
- "AbstractController::ActionNotFound" => :not_found,
- "ActionController::MethodNotAllowed" => :method_not_allowed,
- "ActionController::UnknownHttpMethod" => :method_not_allowed,
- "ActionController::NotImplemented" => :not_implemented,
- "ActionController::UnknownFormat" => :not_acceptable,
- "ActionController::InvalidAuthenticityToken" => :unprocessable_entity,
- "ActionController::InvalidCrossOriginRequest" => :unprocessable_entity,
- "ActionDispatch::ParamsParser::ParseError" => :bad_request,
- "ActionController::BadRequest" => :bad_request,
- "ActionController::ParameterMissing" => :bad_request,
- "Rack::QueryParser::ParameterTypeError" => :bad_request,
- "Rack::QueryParser::InvalidParameterError" => :bad_request
+ "ActionController::RoutingError" => :not_found,
+ "AbstractController::ActionNotFound" => :not_found,
+ "ActionController::MethodNotAllowed" => :method_not_allowed,
+ "ActionController::UnknownHttpMethod" => :method_not_allowed,
+ "ActionController::NotImplemented" => :not_implemented,
+ "ActionController::UnknownFormat" => :not_acceptable,
+ "ActionController::InvalidAuthenticityToken" => :unprocessable_entity,
+ "ActionController::InvalidCrossOriginRequest" => :unprocessable_entity,
+ "ActionDispatch::Http::Parameters::ParseError" => :bad_request,
+ "ActionController::BadRequest" => :bad_request,
+ "ActionController::ParameterMissing" => :bad_request,
+ "Rack::QueryParser::ParameterTypeError" => :bad_request,
+ "Rack::QueryParser::InvalidParameterError" => :bad_request
)
cattr_accessor :rescue_templates
diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb
deleted file mode 100644
index b23b6fc62f..0000000000
--- a/actionpack/lib/action_dispatch/middleware/params_parser.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require "action_dispatch/http/request"
-
-module ActionDispatch
- # ActionDispatch::ParamsParser works for all the requests having any Content-Length
- # (like POST). It takes raw data from the request and puts it through the parser
- # that is picked based on Content-Type header.
- #
- # In case of any error while parsing data ParamsParser::ParseError is raised.
- module ParamsParser
- # Raised when raw data from the request cannot be parsed by the parser
- # defined for request's content mime type.
- class ParseError < StandardError
- def initialize
- super($!.message)
- end
- end
- end
-end
diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb
index d0cd32a242..b6810b3392 100644
--- a/actionpack/test/dispatch/request/json_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb
@@ -75,7 +75,7 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest
begin
$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 }
+ exception = assert_raise(ActionDispatch::Http::Parameters::ParseError) { post "/parse", json, "CONTENT_TYPE" => "application/json", "action_dispatch.show_exceptions" => false }
assert_equal JSON::ParserError, exception.cause.class
assert_equal exception.cause.message, exception.message
ensure
diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb
index d8f673c212..3513534d72 100644
--- a/actionpack/test/dispatch/show_exceptions_test.rb
+++ b/actionpack/test/dispatch/show_exceptions_test.rb
@@ -11,7 +11,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
begin
raise StandardError.new
rescue
- raise ActionDispatch::ParamsParser::ParseError
+ raise ActionDispatch::Http::Parameters::ParseError
end
when "/method_not_allowed"
raise ActionController::MethodNotAllowed, "PUT"
diff --git a/guides/source/configuring.md b/guides/source/configuring.md
index 3df8a0ed26..022886a122 100644
--- a/guides/source/configuring.md
+++ b/guides/source/configuring.md
@@ -462,23 +462,23 @@ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`.
```ruby
config.action_dispatch.rescue_responses = {
- 'ActionController::RoutingError' => :not_found,
- 'AbstractController::ActionNotFound' => :not_found,
- 'ActionController::MethodNotAllowed' => :method_not_allowed,
- 'ActionController::UnknownHttpMethod' => :method_not_allowed,
- 'ActionController::NotImplemented' => :not_implemented,
- 'ActionController::UnknownFormat' => :not_acceptable,
- 'ActionController::InvalidAuthenticityToken' => :unprocessable_entity,
- 'ActionController::InvalidCrossOriginRequest' => :unprocessable_entity,
- 'ActionDispatch::ParamsParser::ParseError' => :bad_request,
- 'ActionController::BadRequest' => :bad_request,
- 'ActionController::ParameterMissing' => :bad_request,
- 'Rack::QueryParser::ParameterTypeError' => :bad_request,
- 'Rack::QueryParser::InvalidParameterError' => :bad_request,
- 'ActiveRecord::RecordNotFound' => :not_found,
- 'ActiveRecord::StaleObjectError' => :conflict,
- 'ActiveRecord::RecordInvalid' => :unprocessable_entity,
- 'ActiveRecord::RecordNotSaved' => :unprocessable_entity
+ 'ActionController::RoutingError' => :not_found,
+ 'AbstractController::ActionNotFound' => :not_found,
+ 'ActionController::MethodNotAllowed' => :method_not_allowed,
+ 'ActionController::UnknownHttpMethod' => :method_not_allowed,
+ 'ActionController::NotImplemented' => :not_implemented,
+ 'ActionController::UnknownFormat' => :not_acceptable,
+ 'ActionController::InvalidAuthenticityToken' => :unprocessable_entity,
+ 'ActionController::InvalidCrossOriginRequest' => :unprocessable_entity,
+ 'ActionDispatch::Http::Parameters::ParseError' => :bad_request,
+ 'ActionController::BadRequest' => :bad_request,
+ 'ActionController::ParameterMissing' => :bad_request,
+ 'Rack::QueryParser::ParameterTypeError' => :bad_request,
+ 'Rack::QueryParser::InvalidParameterError' => :bad_request,
+ 'ActiveRecord::RecordNotFound' => :not_found,
+ 'ActiveRecord::StaleObjectError' => :conflict,
+ 'ActiveRecord::RecordInvalid' => :unprocessable_entity,
+ 'ActiveRecord::RecordNotSaved' => :unprocessable_entity
}
```