Get the standard message for any HTTP status code.
Code
Generalconst HTTP_STATUS = {
// 1xx Informational
100: 'Continue', 101: 'Switching Protocols', 102: 'Processing',
// 2xx Success
200: 'OK', 201: 'Created', 202: 'Accepted', 204: 'No Content',
// 3xx Redirection
301: 'Moved Permanently', 302: 'Found', 304: 'Not Modified', 307: 'Temporary Redirect', 308: 'Permanent Redirect',
// 4xx Client Error
400: 'Bad Request', 401: 'Unauthorized', 403: 'Forbidden', 404: 'Not Found',
405: 'Method Not Allowed', 408: 'Request Timeout', 409: 'Conflict', 410: 'Gone',
413: 'Payload Too Large', 415: 'Unsupported Media Type', 418: "I'm a Teapot",
422: 'Unprocessable Entity', 429: 'Too Many Requests',
// 5xx Server Error
500: 'Internal Server Error', 501: 'Not Implemented', 502: 'Bad Gateway',
503: 'Service Unavailable', 504: 'Gateway Timeout'
};
return HTTP_STATUS[statusCode] || 'Unknown Status';Parameters
HTTP status code
Browser·fetch() may be limited by CORS
Common Status Codes
| Code | Message | When to Use |
|---|---|---|
| 200 | OK | Successful GET/PUT |
| 201 | Created | Successful POST |
| 204 | No Content | Successful DELETE |
| 400 | Bad Request | Invalid request body |
| 401 | Unauthorized | Missing/invalid auth |
| 403 | Forbidden | Valid auth but no permission |
| 404 | Not Found | Resource doesn't exist |
| 409 | Conflict | Resource state conflict |
| 422 | Unprocessable Entity | Validation failed |
| 429 | Too Many Requests | Rate limited |
| 500 | Internal Server Error | Server bug |
| 503 | Service Unavailable | Maintenance/overload |
Status Code Categories
function getStatusCategory(code) {
if (code >= 100 && code < 200) return 'informational';
if (code >= 200 && code < 300) return 'success';
if (code >= 300 && code < 400) return 'redirection';
if (code >= 400 && code < 500) return 'client-error';
if (code >= 500 && code < 600) return 'server-error';
return 'unknown';
}
More JavaScript Snippets
Add Query Parameter
Add or update a query parameter in a URL string.
Bearer Token Authentication
Make an authenticated HTTP request using Bearer token for JWT or OAuth.
Check Cloudflare Cache Status
Check if a resource is served from Cloudflare's cache by inspecting the CF-Cache-Status header.
CORS Cross-Origin Request
Make a cross-origin HTTP request with CORS headers inspection.
Delayed Response (Test Timeouts)
Request a delayed response to test timeout handling with AbortController.
Download Binary File
Download an image or binary file and convert it to a blob or base64.