From 75dbe788cb8ad9608713a5644b696a507cff83d9 Mon Sep 17 00:00:00 2001 From: Junichi Sato <22004610+sato11@users.noreply.github.com> Date: Tue, 2 Jan 2024 23:15:52 +0900 Subject: [PATCH] Resolve documentational ambiguity over `rescue_responses` [ci-skip] The issue was raised years ago at https://github.com/rails/rails/issues/27128 where everyone involved agreed that the documentation should be worked on, only to leave it forgotten. I believe it is still relevant as the ambiguity remains ever since. Also, two of exceptions which have a seat in the current default have been missing in the documentation so this commit aligns them. --- guides/source/configuring.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 566d642c569ad..38175ccdabfbc 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -1948,16 +1948,25 @@ information. It defaults to `true`. #### `config.action_dispatch.rescue_responses` -Configures what exceptions are assigned to an HTTP status. It accepts a hash and you can specify pairs of exception/status. By default, this is defined as: +Configures what exceptions are assigned to an HTTP status. It accepts a hash and you can specify pairs of exception/status. ```ruby -config.action_dispatch.rescue_responses = { +# It's good to use #[]= or #merge! to respect the default values +config.action_dispatch.rescue_responses['MyAuthenticationError'] = :unauthorized +``` + +Use `ActionDispatch::ExceptionWrapper.rescue_responses` to observe the configuration. By default, it is defined as: + +```ruby +{ '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, + 'ActionDispatch::Http::MimeNegotiation::InvalidType' => :not_acceptable, + 'ActionController::MissingExactTemplate' => :not_acceptable, 'ActionController::InvalidAuthenticityToken' => :unprocessable_entity, 'ActionController::InvalidCrossOriginRequest' => :unprocessable_entity, 'ActionDispatch::Http::Parameters::ParseError' => :bad_request,