HTTP status codes: client errors (4xx)
This course covers the HTTP 4xx status codes, which signal that a request from the client has a problem. It explains how client errors differ from 5xx server errors and what a helpful error response contains. Lessons cover 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 422 Unprocessable Content and 429 Too Many Requests. Each code is shown with Rails examples. The final lesson combines them into a controller pattern with rescue_from, respond_to, custom error pages and a decision tree for choosing a code.
What you'll learn
- ✓How 4xx client errors differ from 5xx server errors
- ✓When to return 400 versus 422 for malformed or invalid requests
- ✓The difference between authentication (401) and authorization (403)
- ✓How 404 works, including 410 Gone, soft 404s and SEO effects
- ✓Rate limiting strategies, the Retry-After header and 429 handling
- ✓Handling client errors in Rails with status symbols, rescue_from and custom error pages
What are client error status codes?
Imagine you walk into a library and ask for a book that doesn't exist. The librarian doesn't apologize: it's not the library's fault. They tell you: "We don't have that book." That's the spirit of a 4xx status code.
Read the full lesson free →Curriculum
7 lessonsWhat are client error status codes?
Introduces 4xx codes as client errors, compares them with 5xx, and gives a decision tree for choosing one.
400 Bad Request
Explains 400 for malformed requests such as broken JSON, wrong Content-Type or bad URL encoding, with Rails examples.
401 Unauthorized and 403 Forbidden
Separates authentication from authorization, showing when to return 401 or 403 and how the WWW-Authenticate header works.
404 Not Found
Covers 404 causes, the 410 Gone alternative, custom error pages, soft 404s, SEO impact and RecordNotFound in Rails.
422 Unprocessable Content
Shows 422 for well-formed requests with invalid data, including Rails validations, JSON error bodies and Turbo form behavior.
429 Too Many Requests and rate limiting
Explains rate limiting strategies, the Retry-After header, exponential backoff, and the Rails rate_limit method and rack-attack gem.
Client errors in Rails
Combines all 4xx codes in Rails using status symbols, a controller pattern, rescue_from, respond_to and custom error pages.