Skip to content

Commit 7c4a623

Browse files
author
Zachary Scott
committed
Merge pull request rails#17076 from yuki24/write-doc-for-rescue-responses
Add documentation about rescue_responses in Configuring [ci skip]
2 parents 4581d04 + 89b8836 commit 7c4a623

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

guides/source/configuring.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,29 @@ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`.
364364
method should be performed on the parameters. See [Security Guide](security.html#unsafe-query-generation)
365365
for more information. It defaults to true.
366366

367+
* `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:
368+
369+
```ruby
370+
config.action_dispatch.rescue_responses = {
371+
'ActionController::RoutingError' => :not_found,
372+
'AbstractController::ActionNotFound' => :not_found,
373+
'ActionController::MethodNotAllowed' => :method_not_allowed,
374+
'ActionController::UnknownHttpMethod' => :method_not_allowed,
375+
'ActionController::NotImplemented' => :not_implemented,
376+
'ActionController::UnknownFormat' => :not_acceptable,
377+
'ActionController::InvalidAuthenticityToken' => :unprocessable_entity,
378+
'ActionDispatch::ParamsParser::ParseError' => :bad_request,
379+
'ActionController::BadRequest' => :bad_request,
380+
'ActionController::ParameterMissing' => :bad_request,
381+
'ActiveRecord::RecordNotFound' => :not_found,
382+
'ActiveRecord::StaleObjectError' => :conflict,
383+
'ActiveRecord::RecordInvalid' => :unprocessable_entity,
384+
'ActiveRecord::RecordNotSaved' => :unprocessable_entity
385+
}
386+
```
387+
388+
Any execptions that are not configured will be assigned to 500 Internal server error.
389+
367390
* `ActionDispatch::Callbacks.before` takes a block of code to run before the request.
368391

369392
* `ActionDispatch::Callbacks.to_prepare` takes a block to run after `ActionDispatch::Callbacks.before`, but before the request. Runs for every request in `development` mode, but only once for `production` or environments with `cache_classes` set to `true`.

0 commit comments

Comments
 (0)