HTTP status debugging
Use when an HTTP request returns an unexpected status code (4xx or 5xx, or a redirect loop), when a user pastes an error like "419 Page Expired", "422 Unprocessable Content", "502 Bad Gateway" or "CORS error", or when debugging API calls between a frontend and a Laravel/PHP or Node backend. Finds the cause from the status code, headers and logs before changing code.
Licence MIT
Source delaparra-original
Download zipHTTP status debugging
Diagnose a failing HTTP request by reading the evidence first: status code, response headers, response body and server logs. Do not change code until you can name the cause.
Workflow
- Reproduce and capture. Get the exact request: method, URL, request headers, body. Prefer
curl -i(shows status line and headers) or the browser DevTools Network tab ("Copy as cURL").
Always sendcurl -i -X POST https://app.test/api/orders \ -H "Accept: application/json" -H "Content-Type: application/json" \ -d '{"product_id": 1}'Accept: application/jsonto an API. Without it, Laravel returns HTML redirects instead of JSON errors, which hides the real problem. - Classify the code using the table below. 4xx means the request is wrong or not allowed; 5xx means the server (or something in front of it) failed.
- Read the server side. Laravel:
storage/logs/laravel.log(tail -f). Nginx:/var/log/nginx/error.log. PHP-FPM: its pool log. Node: process stdout. Docker:docker compose logs -f <service>. - Form one hypothesis, test it, then fix. State: "The 422 happens because field X fails rule Y." Verify with a single changed request before editing code.
- Verify the fix by repeating the exact request from step 1 and confirming the expected status.
Status code reference
| Code | Usual meaning | First things to check |
|---|---|---|
| 200 / 201 / 204 | Success | 204 has no body; don't parse JSON from it |
| 301 / 302 | Redirect | Unexpected redirect to /login = not authenticated; HTTP→HTTPS loop = proxy/TrustProxies config |
| 304 | Not modified | Caching via ETag/If-None-Match; not an error |
| 400 | Malformed request | Invalid JSON body, wrong Content-Type |
| 401 | Not authenticated | Missing/expired token, cookie not sent (credentials: 'include', SameSite) |
| 403 | Authenticated but forbidden | Policy/Gate denies, file permissions, WAF |
| 404 | Route or record not found | php artisan route:list, route model binding, trailing slash, wrong base URL |
| 405 | Method not allowed | GET vs POST mismatch, form method spoofing (@method('PUT')) |
| 409 | Conflict | Duplicate unique key, version conflict |
| 419 | Laravel: CSRF token mismatch / session expired | @csrf in form, X-XSRF-TOKEN header, session domain, SESSION_DOMAIN, Sanctum stateful domains |
| 422 | Validation failed | Read the errors object in the JSON body; match field names |
| 429 | Rate limited | Retry-After header, throttle middleware |
| 500 | Unhandled server error | Log file stack trace; never guess without it |
| 502 | Bad gateway | Upstream (PHP-FPM, Node, container) crashed or not listening; check upstream logs and port |
| 503 | Unavailable | Maintenance mode (php artisan up), overloaded, health check failing |
| 504 | Gateway timeout | Slow query or external call; check timeouts on proxy and PHP |
CORS errors
A "CORS error" in the browser console is not a status code. The browser blocked the response because headers were missing. Check the preflight OPTIONS request in the Network tab: it needs Access-Control-Allow-Origin (exact origin when using credentials, not *), Access-Control-Allow-Methods and Access-Control-Allow-Headers. In Laravel, configure config/cors.php. A CORS error that hides a 500 is common: check the server log too.
Rules
- Never "fix" a 4xx/5xx by catching and swallowing the error.
- Never disable CSRF protection or set CORS to
*with credentials to make an error go away. - Report back: request, observed status, cause, fix, verification result.
Files
LICENSESKILL.mdSOURCE.md
Related terms
- 200 OK
- 201 Created
- 204 No Content
- 206 Partial Content
- 301 Moved Permanently
- 302 Found
- 304 Not Modified
- 400 Bad Request
- 401 Unauthorized
- 403 Forbidden
- 404 Not Found
- 405 Method Not Allowed
- 409 Conflict
- 422 Unprocessable Entity
- 429 Too Many Requests
- 500 Internal Server Error
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
- API (Application Programming Interface)
- CORSError
- curl
- Endpoint
- GraphQL
- Payload
- Polling
- REST (Representational State Transfer)
- scp
- ssh
- Webhook
- WebSocket
- wget
Installing an agent skill in Claude Code, Codex, Cursor and Copilot