Merge pull request #16669 from aantix/dangerous_attribute_error_better_message

Improved the error messaging for the DangerousAttributeError exception
Fix a bug where malformed query strings lead to 500

If a request contains an malformed query string, Rails responds with an
internal server error insted of a bad request. This is because
ActionDispatch::PublicExceptions calls request#formats and it raises an
ActionController::BadRequest from inside ActionDispatch::ShowExceptions,
hence the 500 error.

This commit changes PublicExceptions to catch BadRequest if raised from
request#formats.

fixes #11502