Rails: ArgumentError: Unrecognized status code :request_entity_too_large

43 Views Asked by At

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?

1

There are 1 best solutions below

0
Jon Schneider On

In Rails 4.2, :request_entity_too_large was renamed to :payload_too_large. Use the latter instead. For example, this works in Rails 4.2+:

head :payload_too_large and return if is_too_large?(params[:data])

Source: https://guides.rubyonrails.org/4_2_release_notes.html#changed-status-option-symbols-for-render