HTTP status code symbols for Rails | |
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings. | |
Status Code Symbol | |
1xx Informational | |
100 :continue | |
101 :switching_protocols | |
102 :processing | |
2xx Success | |
200 :ok | |
201 :created | |
202 :accepted | |
203 :non_authoritative_information | |
204 :no_content | |
205 :reset_content | |
206 :partial_content | |
207 :multi_status | |
226 :im_used | |
3xx Redirection | |
300 :multiple_choices | |
301 :moved_permanently | |
302 :found | |
303 :see_other | |
304 :not_modified | |
305 :use_proxy | |
307 :temporary_redirect | |
4xx Client Error | |
400 :bad_request | |
401 :unauthorized | |
402 :payment_required | |
403 :forbidden | |
404 :not_found | |
405 :method_not_allowed | |
406 :not_acceptable | |
407 :proxy_authentication_required | |
408 :request_timeout | |
409 :conflict | |
410 :gone | |
411 :length_required | |
412 :precondition_failed | |
413 :request_entity_too_large | |
414 :request_uri_too_long | |
415 :unsupported_media_type | |
416 :requested_range_not_satisfiable | |
417 :expectation_failed | |
422 :unprocessable_entity | |
423 :locked | |
424 :failed_dependency | |
426 :upgrade_required | |
5xx Server Error | |
500 :internal_server_error | |
501 :not_implemented | |
502 :bad_gateway | |
503 :service_unavailable | |
504 :gateway_timeout | |
505 :http_version_not_supported | |
507 :insufficient_storage | |
510 :not_extended |
This comment has been minimized.
This comment has been minimized.
Found |
This comment has been minimized.
This comment has been minimized.
@juanpastas In Rack::Utils you also have |
This comment has been minimized.
This comment has been minimized.
Cool. Never used them because didn't take the time to find the list. Gonna fork this. Thanks a lot. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
No 3rd party code needed:
|
This comment has been minimized.
This comment has been minimized.
Thanks for sharing this. |
This comment has been minimized.
This comment has been minimized.
(Rails 5.1.4) 416 is wrong. |
This comment has been minimized.
This comment has been minimized.
413 is also wrong now - it should be: |
This comment has been minimized.
This comment has been minimized.
429: Too Many Requests |
This comment has been minimized.
This comment has been minimized.
@AlexVPopov Thanks for sharing :) |
This comment has been minimized.
This comment has been minimized.
This really ought to be in the official Rails Guides. |
This comment has been minimized.
This comment has been minimized.
Missing an important one : https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418 |
This comment has been minimized.
This comment has been minimized.
@liondancer |
This comment has been minimized.
This comment has been minimized.
@danielricecodes already written in official Rails Guides
|
This comment has been minimized.
This comment has been minimized.
OMGGG thanks |
This comment has been minimized.
This comment has been minimized.
Documentation for generic status types are so hard to find. Just leaving this here for future reference: In rspec: https://relishapp.com/rspec/rspec-rails/docs/matchers/have-http-status-matcher |
This comment has been minimized.
This comment has been minimized.
is it possible to include a custom error message statusText with the response? |
This comment has been minimized.
This comment has been minimized.
@alexsmartens : It looks like no, it's not. Or at least it's not easy. A few days ago I was trying to achieve exactly that. I had a nice idea, that you could pass a string for example in (I wanted the status text to be dynamic, so that each render might set it differently - for example providing translated statuses, in line with what all the relevant RFCs say. Merely adding another entry to the Rack::Utils::HTTP_STATUS_CODES was not good enough for me. But even that would not work.) With these changes to the
plus some changes to But then I got into Puma, where the status was again converted to integer, and the status text was being taken again from a hardcoded list of texts (same form as in rack/utils, but it's a separate code). At that point I gave up. The coding itself looks trivial. The real problem lies in testing for backwards compatibility, and - this is the most terrifying part! - talking to various groups of people to accept these changes into their projects. If you feel brave enough, you may try to work on that. |
This comment has been minimized.
Is not there a map inside Rails?