|
| 1 | +export const statusMessages = { |
| 2 | + 100: "Continue", |
| 3 | + 101: "Switching Protocols", |
| 4 | + 102: "Processing", |
| 5 | + 103: "Early Hints", |
| 6 | + 200: "OK", |
| 7 | + 201: "Created", |
| 8 | + 202: "Accepted", |
| 9 | + 203: "Non-Authoritative Information", |
| 10 | + 204: "No Content", |
| 11 | + 205: "Reset Content", |
| 12 | + 206: "Partial Content", |
| 13 | + 207: "Multi-Status", |
| 14 | + 208: "Already Reported", |
| 15 | + 226: "IM Used", |
| 16 | + 300: "Multiple Choices", |
| 17 | + 301: "Moved Permanently", |
| 18 | + 302: "Found", |
| 19 | + 303: "See Other", |
| 20 | + 304: "Not Modified", |
| 21 | + 305: "Use Proxy", |
| 22 | + 307: "Temporary Redirect", |
| 23 | + 308: "Permanent Redirect", |
| 24 | + 400: "Bad Request", |
| 25 | + 401: "Unauthorized", |
| 26 | + 402: "Payment Required", |
| 27 | + 403: "Forbidden", |
| 28 | + 404: "Not Found", |
| 29 | + 405: "Method Not Allowed", |
| 30 | + 406: "Not Acceptable", |
| 31 | + 407: "Proxy Authentication Required", |
| 32 | + 408: "Request Timeout", |
| 33 | + 409: "Conflict", |
| 34 | + 410: "Gone", |
| 35 | + 411: "Length Required", |
| 36 | + 412: "Precondition Failed", |
| 37 | + 413: "Payload Too Large", |
| 38 | + 414: "URI Too Long", |
| 39 | + 415: "Unsupported Media Type", |
| 40 | + 416: "Range Not Satisfiable", |
| 41 | + 417: "Expectation Failed", |
| 42 | + 418: "I'm a Teapot", |
| 43 | + 421: "Misdirected Request", |
| 44 | + 422: "Unprocessable Entity", |
| 45 | + 423: "Locked", |
| 46 | + 424: "Failed Dependency", |
| 47 | + 425: "Too Early", |
| 48 | + 426: "Upgrade Required", |
| 49 | + 428: "Precondition Required", |
| 50 | + 429: "Too Many Requests", |
| 51 | + 431: "Request Header Fields Too Large", |
| 52 | + 451: "Unavailable For Legal Reasons", |
| 53 | + 500: "Internal Server Error", |
| 54 | + 501: "Not Implemented", |
| 55 | + 502: "Bad Gateway", |
| 56 | + 503: "Service Unavailable", |
| 57 | + 504: "Gateway Timeout", |
| 58 | + 505: "HTTP Version Not Supported", |
| 59 | + 506: "Variant Also Negotiates", |
| 60 | + 507: "Insufficient Storage", |
| 61 | + 508: "Loop Detected", |
| 62 | + 509: "Bandwidth Limit Exceeded", |
| 63 | + 510: "Not Extended", |
| 64 | + 511: "Network Authentication Required", |
| 65 | +} |
| 66 | + |
| 67 | +export enum HttpStatus { |
| 68 | + Continue = 100, |
| 69 | + SwitchingProtocols = 101, |
| 70 | + Processing = 102, |
| 71 | + EarlyHints = 103, |
| 72 | + |
| 73 | + OK = 200, |
| 74 | + Created = 201, |
| 75 | + Accepted = 202, |
| 76 | + NonAuthoritativeInformation = 203, |
| 77 | + NoContent = 204, |
| 78 | + ResetContent = 205, |
| 79 | + PartialContent = 206, |
| 80 | + MultiStatus = 207, |
| 81 | + AlreadyReported = 208, |
| 82 | + IMUsed = 226, |
| 83 | + |
| 84 | + MultipleChoices = 300, |
| 85 | + MovedPermanently = 301, |
| 86 | + Found = 302, |
| 87 | + SeeOther = 303, |
| 88 | + NotModified = 304, |
| 89 | + UseProxy = 305, |
| 90 | + TemporaryRedirect = 307, |
| 91 | + PermanentRedirect = 308, |
| 92 | + |
| 93 | + BadRequest = 400, |
| 94 | + Unauthorized = 401, |
| 95 | + PaymentRequired = 402, |
| 96 | + Forbidden = 403, |
| 97 | + NotFound = 404, |
| 98 | + MethodNotAllowed = 405, |
| 99 | + NotAcceptable = 406, |
| 100 | + ProxyAuthenticationRequired = 407, |
| 101 | + RequestTimeout = 408, |
| 102 | + Conflict = 409, |
| 103 | + Gone = 410, |
| 104 | + LengthRequired = 411, |
| 105 | + PreconditionFailed = 412, |
| 106 | + PayloadTooLarge = 413, |
| 107 | + URITooLong = 414, |
| 108 | + UnsupportedMediaType = 415, |
| 109 | + RangeNotSatisfiable = 416, |
| 110 | + ExpectationFailed = 417, |
| 111 | + IAmATeapot = 418, |
| 112 | + MisdirectedRequest = 421, |
| 113 | + UnprocessableEntity = 422, |
| 114 | + Locked = 423, |
| 115 | + FailedDependency = 424, |
| 116 | + TooEarly = 425, |
| 117 | + UpgradeRequired = 426, |
| 118 | + PreconditionRequired = 428, |
| 119 | + TooManyRequests = 429, |
| 120 | + RequestHeaderFieldsTooLarge = 431, |
| 121 | + UnavailableForLegalReasons = 451, |
| 122 | + |
| 123 | + InternalServerError = 500, |
| 124 | + NotImplemented = 501, |
| 125 | + BadGateway = 502, |
| 126 | + ServiceUnavailable = 503, |
| 127 | + GatewayTimeout = 504, |
| 128 | + HttpVersionNotSupported = 505, |
| 129 | + VariantAlsoNegotiates = 506, |
| 130 | + InsufficientStorage = 507, |
| 131 | + LoopDetected = 508, |
| 132 | + BandwidthLimitExceeded = 509, |
| 133 | + NotExtended = 510, |
| 134 | + NetworkAuthenticationRequired = 511, |
| 135 | +} |
| 136 | + |
| 137 | +export type StatusCode = keyof typeof statusMessages |
| 138 | + |
| 139 | +export function isValidStatusCode(statusCode: unknown): statusCode is StatusCode { |
| 140 | + return typeof statusCode === "number" && Object.hasOwn(statusMessages, statusCode) |
| 141 | +} |
0 commit comments