HTTP Status Codes: Complete Reference Guide for Developers

Farouk Ben. - Founder at OdownFarouk Ben.()
HTTP Status Codes: Complete Reference Guide for Developers - Odown - uptime monitoring and status page

HTTP status codes tell the story of your web application's health. When a browser requests a resource from your server, the server responds with a three-digit number that speaks volumes about what happened. These codes aren't just technical trivia - they're diagnostic tools that can save you hours of debugging.

Think of status codes as your server's way of keeping a conversation with the client. They range from the cheerful "200 OK" to the problematic "503 Service Unavailable." Understanding these codes helps you quickly identify and fix issues before they impact users.

5xx Server Error Codes Explained

Server errors indicate that the request hit your server successfully, but something went wrong on the server's end. These are the issues that wake you up at 3 AM.

What is a 503 Service Unavailable Error?

The 503 Service Unavailable error signals that your server can't handle the request temporarily. This happens when:

  • Your server is overloaded with requests
  • The database server is down
  • Maintenance is currently happening
  • The application server crashed unexpectedly
  • Load balancers can't find healthy backend servers

Diagnosing 503 Errors: Check server logs immediately, verify dependent services are running, and monitor system resources like CPU and memory.

Common Causes of 502 Bad Gateway

The 502 Bad Gateway error appears when your server acts as a proxy and receives an invalid response from the upstream server. Common triggers include:

  • Upstream server is down or unreachable
  • Backend application crashed or timed out
  • Database connectivity problems
  • Firewall blocking necessary connections
  • DNS resolution failures for internal services

Quick Fix Approaches: Restart the application server, check network connectivity between servers, verify upstream service status, and review proxy configuration.

Other Critical 5xx Errors

  • 500 Internal Server Error - Something went wrong, but the server doesn't know what. Check error logs for stack traces and recent code changes.
  • 504 Gateway Timeout - The server waited too long for a response from another server. Look for slow database queries or unresponsive APIs.
  • 501 Not Implemented - The server doesn't support the functionality required. Verify API endpoint implementation.

4xx Client Error Status Codes

Client errors mean the request has problems - bad syntax, invalid authentication, or forbidden access. These errors often stem from user mistakes or application bugs.

Common 4xx Errors

  • 400 Bad Request - Malformed request syntax, invalid request framing, or deceptive request routing. Check request parameters and format.
  • 401 Unauthorized - Authentication required but missing or invalid. Verify API keys, tokens, or credentials.
  • 403 Forbidden - Server understood but refuses to authorize. Check user permissions and access control lists.
  • 404 Not Found - The resource doesn't exist. Confirm URL paths, deleted resources, and routing configurations.
  • 405 Method Not Allowed - HTTP method isn't supported for the resource. Verify API documentation and request methods.
  • 408 Request Timeout - Server timed out waiting for the request. Examine network latency and request processing time.
  • 429 Too Many Requests - Rate limiting kicked in. Review API usage limits and implement request throttling.

Monitoring and Alerting for Critical HTTP Status Codes

Tracking status codes isn't enough - you need intelligent alerting that helps you respond to problems quickly. The right monitoring setup alerts you to patterns of errors before they become outages.

Setting Up Custom Alerts for Error Responses

Configure monitoring to catch various error patterns:

Single Error Alerts

  • Alert on any 5xx error for critical endpoints
  • Monitor 500 errors for unexpected application crashes
  • Track 503 errors during maintenance windows

Pattern-Based Monitoring

  • Alert when error rates exceed 5% of total requests
  • Monitor for sustained periods of 429 errors
  • Watch for cascading 502 errors across services

Response Time Alerts

  • Combine status codes with response time metrics
  • Alert on slow requests that might trigger 504 errors
  • Monitor for patterns that precede 503 errors

Example Alert Configuration:

{
"alert_name": "Critical Error Monitoring",
"conditions": {
"status_codes": [500, 502, 503, 504],
"threshold": 2,
"timeframe": "5 minutes"
},
"notifications": ["email", "sms", "slack"]
}

Best Practices for Status Code Monitoring

Create Error Code Hierarchies

  • Critical: 5xx errors on payment and checkout flows
  • High: Authentication errors (401, 403) on login systems
  • Medium: 404 errors on content pages
  • Low: Rate limiting (429) on non-critical APIs

Implement Smart Alerting

  • Group related alerts to avoid notification spam
  • Set different severity levels for business hours vs. off-hours
  • Configure escalation paths based on error persistence
  • Track error rate trends over time
  • Watch for gradual increases in specific error types
  • Identify patterns that predict upcoming issues

Status Code Implementation Checklist

Client Side

  • Handle 401 with automatic re-authentication
  • Retry 503 errors with exponential backoff
  • Display user-friendly messages for 404 errors
  • Implement rate limiting respect for 429 responses

Server Side

  • Return appropriate status codes consistently
  • Include helpful error messages in response bodies
  • Log all 5xx errors with stack traces
  • Implement proper error handling middleware

Testing and Debugging Status Codes

Local Testing

# Test specific status codes
curl -I http://your-api.com/endpoint

# Check response headers
curl -v http://your-api.com/

# Test timeout scenarios
curl --max-time 5 http://your-api.com/slow-endpoint

Production Debugging

  • Check server logs for error patterns
  • Monitor response times alongside status codes
  • Use browser developer tools for client-side analysis
  • Implement request tracing for complex workflows

Common Status Code Troubleshooting Scenarios

Scenario 1: Sudden 502 Errors

  • Check application server health
  • Verify database connectivity
  • Review recent deployments
  • Test upstream service availability

Scenario 2: Intermittent 503 Errors

  • Monitor server load metrics
  • Check auto-scaling configurations
  • Verify connection pool settings
  • Review resource consumption patterns

Scenario 3: Increasing 429 Errors

  • Analyze request patterns by client
  • Review rate limiting configurations
  • Check for potential abuse or DDoS
  • Implement request queuing if needed

Status Code Reference Summary

Information (1xx)

  • 100: Continue - Server received request headers
  • 101: Switching Protocols - Protocol changes accepted

Success (2xx)

  • 200: OK - Request succeeded completely
  • 201: Created - New resource created successfully
  • 204: No Content - Request processed, no content to return
  • 206: Partial Content - Range request partially fulfilled

Redirection (3xx)

  • 301: Moved Permanently - Resource has new location
  • 302: Found - Resource temporarily at different URI
  • 304: Not Modified - Cached version still valid
  • 307: Temporary Redirect - Method and body must not change

Client Error (4xx)

  • 400: Bad Request - Invalid request syntax
  • 401: Unauthorized - Authentication required
  • 403: Forbidden - Server refuses to authorize
  • 404: Not Found - Resource doesn't exist
  • 405: Method Not Allowed - Unsupported method
  • 408: Request Timeout - Server timed out
  • 429: Too Many Requests - Rate limit exceeded

Server Error (5xx)

  • 500: Internal Server Error - Generic server error
  • 501: Not Implemented - Server lacks capability
  • 502: Bad Gateway - Invalid upstream response
  • 503: Service Unavailable - Server temporarily unavailable
  • 504: Gateway Timeout - Upstream server timeout

Ready to monitor your application's HTTP status codes effectively?

Use Odown and get notified immediately when errors impact your users.