In my Rails controller, in a method that handles an HTTP POST, I'm trying to write code that'll return an HTTP 413 response to the client if the value of the data param in the request payload is too large.
Per several sources (e.g. 1, 2), the Rails symbol for HTTP 413 is :request_entity_too_large.
My line of code is:
head :request_entity_too_large and return if too_large?(params[:data])
(too_large? is a private method that I have defined elsewhere in my controller.)
This line is throwing this error at runtime: ArgumentError: Unrecognized status code :request_entity_too_large.
I have a similar line of code that instead returns :unsupported_media_type; that one is working as expected.
What's the problem with my line that attempts to return :request_entity_too_large?
In Rails 4.2,
:request_entity_too_largewas renamed to:payload_too_large. Use the latter instead. For example, this works in Rails 4.2+:Source: https://guides.rubyonrails.org/4_2_release_notes.html#changed-status-option-symbols-for-render