DELAPARRA
Index
Color
NL

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 zip

HTTP 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

  1. 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").
    curl -i -X POST https://app.test/api/orders \
      -H "Accept: application/json" -H "Content-Type: application/json" \
      -d '{"product_id": 1}'
    
    Always send Accept: application/json to an API. Without it, Laravel returns HTML redirects instead of JSON errors, which hides the real problem.
  2. 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.
  3. 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>.
  4. 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.
  5. 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

  • LICENSE
  • SKILL.md
  • SOURCE.md

Related terms

Installing an agent skill in Claude Code, Codex, Cursor and Copilot