A structured laboratory for analyzing common API failure modes. This repository provides an intentional failure lab to practice diagnosing HTTP errors and understanding root causes in distributed systems.
| Status Code | Type | Common Support Root Causes |
|---|---|---|
| 401 | Unauthorized | Invalid API key, expired token, or missing header. |
| 403 | Forbidden | Valid token but insufficient permissions (e.g., scoping issue). |
| 404 | Not Found | Resource deleted, wrong endpoint path, or DNS propagation delay. |
| 500 | Internal Error | Code crash, database disconnection, or unhandled exception. |
| 504 | Gateway Timeout | Upstream service delay or Load Balancer idle timeout exceeded. |
- Does the request reach the server?
- No: Check DNS, VPC, and Security Group (4xx or Timeout).
- Yes: Examine application logs (
journalctl/docker logs).
- Is it a Client error (4xx) or Server error (5xx)?
- 401/403: Verify credentials and header format (
Bearertoken prefix?). - 404: Confirm URL path and parameters via documentation.
- 500: Check stack trace for code-level failures or resource exhaustion.
- 401/403: Verify credentials and header format (
- Is it a latency issue (Timeout)?
- Check upstream dependencies and database query execution times.
- Symptom: User provides correct password but gets 401.
- Root Cause: Often a case-sensitivity issue in the username field or an extra space in the input.
- Symptom: Token is valid for
/api/v1/pingbut fails for/api/v1/data. - Root Cause: The session token lacks the required
adminscope required for this specific resource.
- Symptom: Client expects a resource but it's missing.
- Root Cause: The resource ID exceeds the database sequence or was manually removed from the system.
- Symptom: Service returns generic 500 error.
- Root Cause: Unhandled exception (e.g.,
ZeroDivisionErrororDatabaseConnectionLost) during request processing.
- Launch the lab:
python app/api.py - Test scenarios using
curl:# Test 401 curl -X POST http://localhost:8000/login -d '{"username": "admin", "password": "wrong-password"}' # Test 403 curl -H "Authorization: Bearer wrong-token" http://localhost:8000/api/v1/data # Test 500 curl http://localhost:8000/api/v1/trigger-error
docker build -t api-failure-lab .
docker run -p 8000:8000 api-failure-lab