# 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](<https://delaparra-services.nl/skills/http-status-debugging/download>)   

# 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. 
1. **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. 
1. **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> `. 
1. **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. 
1. **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

 

- [200 OK](<https://delaparra-services.nl/knowledge-hub/200-ok>) 
- [201 Created](<https://delaparra-services.nl/knowledge-hub/201-created>) 
- [204 No Content](<https://delaparra-services.nl/knowledge-hub/204-no-content>) 
- [206 Partial Content](<https://delaparra-services.nl/knowledge-hub/206-partial-content>) 
- [301 Moved Permanently](<https://delaparra-services.nl/knowledge-hub/301-moved-permanently>) 
- [302 Found](<https://delaparra-services.nl/knowledge-hub/302-found>) 
- [304 Not Modified](<https://delaparra-services.nl/knowledge-hub/304-not-modified>) 
- [400 Bad Request](<https://delaparra-services.nl/knowledge-hub/400-bad-request>) 
- [401 Unauthorized](<https://delaparra-services.nl/knowledge-hub/401-unauthorized>) 
- [403 Forbidden](<https://delaparra-services.nl/knowledge-hub/403-forbidden>) 
- [404 Not Found](<https://delaparra-services.nl/knowledge-hub/404-not-found>) 
- [405 Method Not Allowed](<https://delaparra-services.nl/knowledge-hub/405-method-not-allowed>) 
- [409 Conflict](<https://delaparra-services.nl/knowledge-hub/409-conflict>) 
- [422 Unprocessable Entity](<https://delaparra-services.nl/knowledge-hub/422-unprocessable-entity>) 
- [429 Too Many Requests](<https://delaparra-services.nl/knowledge-hub/429-too-many-requests>) 
- [500 Internal Server Error](<https://delaparra-services.nl/knowledge-hub/500-internal-server-error>) 
- [502 Bad Gateway](<https://delaparra-services.nl/knowledge-hub/502-bad-gateway>) 
- [503 Service Unavailable](<https://delaparra-services.nl/knowledge-hub/503-service-unavailable>) 
- [504 Gateway Timeout](<https://delaparra-services.nl/knowledge-hub/504-gateway-timeout>) 
- [API (Application Programming Interface)](<https://delaparra-services.nl/knowledge-hub/api-application-programming-interface>) 
- [CORSError](<https://delaparra-services.nl/knowledge-hub/corserror>) 
- [curl](<https://delaparra-services.nl/knowledge-hub/curl>) 
- [Endpoint](<https://delaparra-services.nl/knowledge-hub/endpoint>) 
- [GraphQL](<https://delaparra-services.nl/knowledge-hub/graphql>) 
- [Payload](<https://delaparra-services.nl/knowledge-hub/payload>) 
- [Polling](<https://delaparra-services.nl/knowledge-hub/polling>) 
- [REST (Representational State Transfer)](<https://delaparra-services.nl/knowledge-hub/rest-representational-state-transfer>) 
- [scp](<https://delaparra-services.nl/knowledge-hub/scp>) 
- [ssh](<https://delaparra-services.nl/knowledge-hub/ssh>) 
- [Webhook](<https://delaparra-services.nl/knowledge-hub/webhook>) 
- [WebSocket](<https://delaparra-services.nl/knowledge-hub/websocket>) 
- [wget](<https://delaparra-services.nl/knowledge-hub/wget>)

 

[Installing an agent skill in Claude Code, Codex, Cursor and Copilot](<https://delaparra-services.nl/manuals/een-skill-installeren-in-je-ai-assistent>)

[HTML version](https://delaparra-services.nl/skills/http-status-debugging)
