DEV Community

Cover image for Ruby on Rails HTTP Status codes
Gonzalo Robaina
Gonzalo Robaina

Posted on

Ruby on Rails HTTP Status codes

Handling different HTTP status codes is not uncommon when working on a Rails application (or especially on an API).

We eventually get to know some of them, but the truth is that there are a lot. The good news is that if you're writing a Ruby on Rails application, there are mappings to handle the status codes by their names.

You can quickly take a look at the list of status codes by simply loading a rails console bundle exec rails console and then checking Rack::Utils::HTTP_STATUS_CODES or Rack::Utils::SYMBOL_TO_STATUS_CODE to get the whole list of supported status codes on rails.

The lists below contain all the supported status codes on Rails, their full names, and the corresponding Ruby symbols.


HTTP Informational Codes (1xx)

100 Continue (:continue)
It is one of the informational HTTP responses returned by the server. It indicates that the HTTP session is progressing as expected and is asking the client to continue to the next step.

101 Switching Protocols (:switching_protocols)
It is an informational HTTP response returned by the server. It indicates that the HTTP session can continue, and the server is switching to a new protocol.

102 Processing (:processing)
It is an informational HTTP response that is sent by a server to inform the client that there will be a significant delay before the final HTTP response is sent and that a potentially long period will pass before receiving the final HTTP response.

103 Early Hints (:early_hints)
It is an informational HTTP response that the server can use to send HTTP headers to a client in advance of a final HTTP response.


HTTP Successful Codes (2xx)

200 OK (:ok)
The server returns it to indicate success. The meaning of success and the accompanying message body vary based on the HTTP request that was sent.

201 Created (:created)
The server returns it to indicate that a resource was successfully created by the HTTP request.

202 Accepted (:accepted)
The server returns it to indicate that an HTTP request has been received, although the processing still needs to be completed, and ultimately, the HTTP request may not be fulfilled.

203 Non-Authoritative Information (:non_authoritative_information)
It is an HTTP status code returned by a proxy to indicate that the HTTP request was successful, but the message body has been modified.

204 No Content (:no_content)
The server returns it to indicate that an HTTP request has been successfully completed, and there is no message body.

205 Reset Content (:reset_content)
The server returns it to instruct the client to reset the document view. A document in this context can be an HTML form, for example.

206 Partial Content (:partial_content)
The server returns it to indicate that an HTTP request has been successfully completed, and the message body contains the requested data ranges.

207 Multi-Status (:multi_status)
The server returns it in cases where it is relevant to relay information about multiple resources.

208 Already Reported (:already_reported)
The server returns it in cases where an HTTP response has already been given about a specific resource.

226 IM Used (:im_used)
The server returns it to indicate that it has fulfilled a GET request that was sent with an A-IM header included, and the HTTP response is the result of one or more Instance Manipulations (IMs).


HTTP Redirection Codes (3xx)

300 Multiple Choices (:multiple_choices)
The server returns it to indicate that more than one HTTP response is available as a result of the HTTP request.

301 Moved Permanently (:moved_permanently)
The server returns it to indicate that the resource has been given a new permanent location.

302 Found (:found)
Previously known as “Moved Temporarily", the server returns it to indicate that the client redirects to a new location specified within the Location HTTP header. Because HTTP response is temporary, it is expected to be revalidated upon the next time the URI is requested.

303 See Other (:see_other)
The server returns it to indicate that the supplied Location does not link directly to the recently uploaded resource. Rather, it links to an alternative page, such as an upload confirmation message.

304 Not Modified (:not_modified)
The server returns it to indicate a successful HTTP request, yet sending the data associated with the resource is unnecessary.

305 Use Proxy (:use_proxy)
It is a deprecated HTTP status code returned by an origin server to indicate that the requested resource can only be accessed through a proxy.

307 Temporary Redirect (:temporary_redirect)
The server returns it to indicate that the requested resource has been temporarily moved to a new location.

308 Permanent Redirect (:permanent_redirect)
The server returns it to indicate that the requested resource has been permanently moved to a new location.


HTTP Client Error Codes (4xx)

400 Bad Request (:bad_request)
It is a generic client error that is normally returned by the server to indicate that the client did something wrong.

401 Unauthorized (:unauthorized)
The server returns a client error to indicate that the HTTP request has to be authenticated and that appropriate login credentials have not yet been received.

402 Payment Required (:payment_required)
The server returns a client error to indicate that payment is required before the client can access the requested resource.

403 Forbidden (:forbidden)
It is a client error that the server returns to indicate that the client does not have access to the requested resource and does not offer an Authentication scheme by which access can be granted.

404 Not Found (:not_found)
It is a common and general client error that the server returns to indicate that a resource can not be found at the specified address.

405 Method Not Allowed (:method_not_allowed)
It is a client error that the server returns to indicate that the resource specified by the request exists, but the requested HTTP method is not allowed.

406 Not Acceptable (:not_acceptable)
It is a client error returned by the server to indicate that the resource exists, but the proactive Content Negotiation engaged in by the client using a relevant HTTP request header was not satisfactory, and the server does not supply a default in lieu.

407 Proxy Authentication Required (:proxy_authentication_required)
The server returns a client error to indicate that the request has to be authenticated for the client to use a proxy.

408 Request Timeout (:request_timeout)
It is a client error that the server returns to indicate that a request is coming in too slowly from a client, and it is unwilling to wait for it to be completed, thus terminating the connection.

409 Conflict (:conflict)
It is a client error that is returned by the server to indicate that the request can not be satisfied because the current state is incompatible with what is required.

410 Gone (:gone)
It is a client error that is returned by the server to indicate that the requested resource is permanently unavailable.

411 Length Required (:length_required)
It is a client error that is returned by the server to indicate that the request cannot be completed because the Content-Length HTTP header field is absent.

412 Precondition Failed (:precondition_failed)
The server returns a client error to indicate that one or more of the client-specified conditions in the request have failed.

413 Content Too Large (:content_too_large)
It is a client error that is returned by the server in cases where the client has initiated a request containing a message body larger than the server is willing to accept for processing.

414 URI Too Long (:uri_too_long)
It is a client error that is returned by the server to indicate that the URI exceeds the length that it allows.

415 Unsupported Media Type (:unsupported_media_type)
It is a client error that the server returns to indicate that the content of a message body is not supported.

416 Range Not Satisfiable (:range_not_satisfiable)
It is a client error that the server returns to indicate that the range or ranges specified by the client were not retrievable.

417 Expectation Failed (:expectation_failed)
It is a client error that the server returns to indicate that the conditions set by the client using the Expect header can not be satisfied.

421 Misdirected Request (:misdirected_request)
The server returns it to indicate that it has received a request not intended for it.

422 Unprocessable Content (:unprocessable_entity)
It is a client error returned by the server to indicate that it understands the content type and the syntax is correct, but it cannot process the instructions specified by the request.

423 Locked (:locked)
It is a client error that is returned by the server to indicate that the target file or folder is locked.

424 Failed Dependency (:failed_dependency)
It is a client error returned by the server as part of a 207 Multi-Status response and is used to indicate that the requested operation can not be performed because it depends on another failed action.

425 Too Early (:too_early)
It is a client error that the server returns to indicate that it has received the request but is not going to process it because there is a risk of it being replayed.

426 Upgrade Required (:upgrade_required)
A client error returned by the server indicates that the server is unwilling to process the request using the current protocol.

428 Precondition Required (:precondition_required)
The server returns it to indicate that HTTP requests of this type must be made conditionally, yet no precondition was included.

429 Too Many Requests (:too_many_requests)
The server returns it to indicate that too many HTTP requests have been made within the allowed time.

431 Request Header Fields Too Large (:request_header_fields_too_large)
The server returns it to indicate that the HTTP headers are too large.

451 Unavailable for Legal Reasons (:unavailable_for_legal_reasons)
The server returns it to indicate that the content requested is unavailable due to a legal or legislated demand.


HTTP Server Error Codes (5xx)

500 Internal Server Error (:internal_server_error)
It is a generic catch-all server error message generally used if a more specific one is unavailable.

501 Not Implemented (:not_implemented)
It is a server error message that is returned to indicate that it does not support a specific feature that is required to complete the HTTP request.

502 Bad Gateway (:bad_gateway)
It is a server error message returned to indicate that it is acting as a proxy or gateway and has received an invalid response from the upstream server.

503 Service Unavailable (:service_unavailable)
It is a server error message returned when the HTTP request cannot be completed because the page or resource is unavailable, and the problem is assumed to be temporary.

504 Gateway Timeout (:gateway_timeout)
It is a server error message that is returned to indicate that it is acting as a proxy or gateway and it has received no HTTP response from the upstream server.

505 HTTP Version Not Supported (:http_version_not_supported)
It is a server error message that indicates the server is unwilling to process the HTTP request using the major version of HTTP that was used in the HTTP request message.

506 Variant Also Negotiates (:variant_also_negotiates)
It is a server error message that occurs during Transparent Content Negotiation. It is an internal misconfiguration error that occurs when a specified endpoint is not a valid HTTP endpoint.

507 Insufficient Storage (:insufficient_storage)
It is a server error message that indicates the server does not have sufficient space to accommodate the HTTP request.

508 Loop Detected (:loop_detected)
It indicates that the server has terminated the directory tree request because an infinite loop has been detected.

509 Bandwidth Limit Exceeded (:bandwidth_limit_exceeded)
It is an unofficial server error specific to Apache Web Server and cPanel that indicates that the web hosting client has exceeded the bandwidth allotment on the server side.

510 Not Extended (:not_extended)
It is a server error that indicates that an extended HTTP request (in the context of RFC 2774) is required but is not used.

511 Network Authentication Required (:network_authentication_required)
It is a server error captive portals use to inform HTTP clients that they must complete a sign-in after connecting to a network.


That's a lot of codes 😅
I'll keep that table updated as new codes get added.
(Last updated September 26, 2024)

Top comments (0)