|
| 1 | +const STATUS_TEXT: Record<number, string> = { |
| 2 | + 400: "Bad Request", |
| 3 | + 401: "Unauthorized", |
| 4 | + 402: "Payment Required", |
| 5 | + 403: "Forbidden", |
| 6 | + 404: "Not Found", |
| 7 | + 405: "Method Not Allowed", |
| 8 | + 406: "Not Acceptable", |
| 9 | + 407: "Proxy Authentication Required", |
| 10 | + 408: "Request Timeout", |
| 11 | + 409: "Conflict", |
| 12 | + 410: "Gone", |
| 13 | + 411: "Length Required", |
| 14 | + 412: "Precondition Failed", |
| 15 | + 413: "Content Too Large", |
| 16 | + 414: "URI Too Long", |
| 17 | + 415: "Unsupported Media Type", |
| 18 | + 416: "Range Not Satisfiable", |
| 19 | + 417: "Expectation Failed", |
| 20 | + 418: "I'm a Teapot", |
| 21 | + 421: "Misdirected Request", |
| 22 | + 422: "Unprocessable Entity", |
| 23 | + 423: "Locked", |
| 24 | + 424: "Failed Dependency", |
| 25 | + 425: "Too Early", |
| 26 | + 426: "Upgrade Required", |
| 27 | + 428: "Precondition Required", |
| 28 | + 429: "Too Many Requests", |
| 29 | + 431: "Request Header Fields Too Large", |
| 30 | + 451: "Unavailable For Legal Reasons", |
| 31 | + 500: "Internal Server Error", |
| 32 | + 501: "Not Implemented", |
| 33 | + 502: "Bad Gateway", |
| 34 | + 503: "Service Unavailable", |
| 35 | + 504: "Gateway Timeout", |
| 36 | + 505: "HTTP Version Not Supported", |
| 37 | + 506: "Variant Also Negotiates", |
| 38 | + 507: "Insufficient Storage", |
| 39 | + 508: "Loop Detected", |
| 40 | + 510: "Not Extended", |
| 41 | + 511: "Network Authentication Required", |
| 42 | +}; |
| 43 | + |
| 44 | +/** |
| 45 | + * Returns the standard HTTP reason phrase for a status code, |
| 46 | + * or `"Unknown Status Code"` if the code is not recognized. |
| 47 | + */ |
| 48 | +export function getStatusText(status: number): string { |
| 49 | + return STATUS_TEXT[status] ?? "Unknown Status Code"; |
| 50 | +} |
0 commit comments