├── .eslintignore ├── .eslintrc.json ├── .github └── workflows │ └── node.js.yml ├── .gitignore ├── LICENSE ├── README.md ├── codes.json ├── jest.config.js ├── package-lock.json ├── package.json ├── scripts ├── build.sh ├── tsconfig.json └── update-codes.ts ├── src ├── index.test.ts ├── index.ts ├── legacy.ts ├── reason-phrases.ts ├── status-codes.ts ├── utils-functions.ts └── utils.ts ├── test ├── v1.d.ts └── v1.js ├── tsconfig-cjs.json ├── tsconfig-es.json ├── tsconfig.eslint.json └── tsconfig.json /.eslintignore: -------------------------------------------------------------------------------- 1 | test/v1.js 2 | test/v1.d.ts 3 | src/codes.ts -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "plugins": [ 5 | "@typescript-eslint" 6 | ], 7 | "rules": { 8 | "import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.js", "./scripts/*.ts"]}] 9 | }, 10 | "extends": ["airbnb-typescript/base"], 11 | "parserOptions": { 12 | "project": "./tsconfig.eslint.json" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [10.x, 12.x, 14.x] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v1 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | - run: npm install 28 | - run: npm test 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage.html 2 | .DS_Store 3 | lib-cov 4 | *.seed 5 | *.log 6 | *.csv 7 | *.dat 8 | *.out 9 | *.pid 10 | *.swp 11 | *.swo 12 | benchmarks/graphs 13 | testing 14 | node_modules/ 15 | testing 16 | .coverage_data 17 | cover_html 18 | test.js 19 | .idea 20 | /build/** 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # http-status-codes 2 | 3 | Constants enumerating the HTTP status codes. Based on the [Java Apache HttpStatus API](http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpStatus.html). 4 | 5 | All status codes defined in the following RFCs are supported: 6 | * RFC1945 (HTTP/1.0) 7 | * RFC2616 (HTTP/1.1) 8 | * RFC7231 (HTTP/1.1: Semantics and Content) 9 | * RFC2518 (WebDAV) 10 | * RFC6585 (Additional HTTP Status Codes) 11 | * RFC7538 (Permanent Redirect) 12 | * RFC8297 (An HTTP Status Code for Indicating Hints) 13 | 14 | TypeScript or JavaScript. Completely library agnostic. No dependencies. 15 | 16 | ## Installation 17 | 18 | ```console 19 | npm install http-status-codes --save 20 | ``` 21 | 22 | ## Usage (express 4.x) 23 | 24 | ```typescript 25 | import { 26 | ReasonPhrases, 27 | StatusCodes, 28 | getReasonPhrase, 29 | getStatusCode, 30 | } from 'http-status-codes'; 31 | 32 | response 33 | .status(StatusCodes.OK) 34 | .send(ReasonPhrases.OK); 35 | 36 | response 37 | .status(StatusCodes.INTERNAL_SERVER_ERROR) 38 | .send({ 39 | error: getReasonPhrase(StatusCodes.INTERNAL_SERVER_ERROR) 40 | }); 41 | 42 | response 43 | .status(getStatusCode('Internal Server Error')) 44 | .send({ 45 | error: 'Internal Server Error' 46 | }); 47 | ``` 48 | 49 | ## Codes 50 | 51 | | Code | Constant | Reason Phrase | 52 | | ---- | ------------------------------- | ------------------------------- | 53 | | 100 | CONTINUE | Continue | 54 | | 101 | SWITCHING_PROTOCOLS | Switching Protocols | 55 | | 102 | PROCESSING | Processing | 56 | | 103 | EARLY_HINTS | Early Hints | 57 | | 200 | OK | OK | 58 | | 201 | CREATED | Created | 59 | | 202 | ACCEPTED | Accepted | 60 | | 203 | NON_AUTHORITATIVE_INFORMATION | Non Authoritative Information | 61 | | 204 | NO_CONTENT | No Content | 62 | | 205 | RESET_CONTENT | Reset Content | 63 | | 206 | PARTIAL_CONTENT | Partial Content | 64 | | 207 | MULTI_STATUS | Multi-Status | 65 | | 300 | MULTIPLE_CHOICES | Multiple Choices | 66 | | 301 | MOVED_PERMANENTLY | Moved Permanently | 67 | | 302 | MOVED_TEMPORARILY | Moved Temporarily | 68 | | 303 | SEE_OTHER | See Other | 69 | | 304 | NOT_MODIFIED | Not Modified | 70 | | 305 | USE_PROXY | Use Proxy | 71 | | 307 | TEMPORARY_REDIRECT | Temporary Redirect | 72 | | 308 | PERMANENT_REDIRECT | Permanent Redirect | 73 | | 400 | BAD_REQUEST | Bad Request | 74 | | 401 | UNAUTHORIZED | Unauthorized | 75 | | 402 | PAYMENT_REQUIRED | Payment Required | 76 | | 403 | FORBIDDEN | Forbidden | 77 | | 404 | NOT_FOUND | Not Found | 78 | | 405 | METHOD_NOT_ALLOWED | Method Not Allowed | 79 | | 406 | NOT_ACCEPTABLE | Not Acceptable | 80 | | 407 | PROXY_AUTHENTICATION_REQUIRED | Proxy Authentication Required | 81 | | 408 | REQUEST_TIMEOUT | Request Timeout | 82 | | 409 | CONFLICT | Conflict | 83 | | 410 | GONE | Gone | 84 | | 411 | LENGTH_REQUIRED | Length Required | 85 | | 412 | PRECONDITION_FAILED | Precondition Failed | 86 | | 413 | REQUEST_TOO_LONG | Request Entity Too Large | 87 | | 414 | REQUEST_URI_TOO_LONG | Request-URI Too Long | 88 | | 415 | UNSUPPORTED_MEDIA_TYPE | Unsupported Media Type | 89 | | 416 | REQUESTED_RANGE_NOT_SATISFIABLE | Requested Range Not Satisfiable | 90 | | 417 | EXPECTATION_FAILED | Expectation Failed | 91 | | 418 | IM_A_TEAPOT | I'm a teapot | 92 | | 419 | INSUFFICIENT_SPACE_ON_RESOURCE | Insufficient Space on Resource | 93 | | 420 | METHOD_FAILURE | Method Failure | 94 | | 421 | MISDIRECTED_REQUEST | Misdirected Request | 95 | | 422 | UNPROCESSABLE_ENTITY | Unprocessable Entity | 96 | | 423 | LOCKED | Locked | 97 | | 424 | FAILED_DEPENDENCY | Failed Dependency | 98 | | 426 | UPGRADE_REQUIRED | Upgrade Required | 99 | | 428 | PRECONDITION_REQUIRED | Precondition Required | 100 | | 429 | TOO_MANY_REQUESTS | Too Many Requests | 101 | | 431 | REQUEST_HEADER_FIELDS_TOO_LARGE | Request Header Fields Too Large | 102 | | 451 | UNAVAILABLE_FOR_LEGAL_REASONS | Unavailable For Legal Reasons | 103 | | 500 | INTERNAL_SERVER_ERROR | Internal Server Error | 104 | | 501 | NOT_IMPLEMENTED | Not Implemented | 105 | | 502 | BAD_GATEWAY | Bad Gateway | 106 | | 503 | SERVICE_UNAVAILABLE | Service Unavailable | 107 | | 504 | GATEWAY_TIMEOUT | Gateway Timeout | 108 | | 505 | HTTP_VERSION_NOT_SUPPORTED | HTTP Version Not Supported | 109 | | 507 | INSUFFICIENT_STORAGE | Insufficient Storage | 110 | | 511 | NETWORK_AUTHENTICATION_REQUIRED | Network Authentication Required | 111 | 112 | ## Migrating from v1.x.x 113 | 114 | http-status-codes v2 is mostly backwards compatible with v1. There is a single breaking change and two recommended changes. 115 | 116 | #### [Breaking Change] 'Server Error' 117 | 118 | The reason phrase for the status code `500` has been changed from `"Server Error"` to `"Internal Server Error"`. This is the correct phrase according to RFC7231. If you are migrating from v1, and have code that relies on the result of `getStatusText(500)` or `getReasonPhrase('Server Error')`, then this could affect you. 119 | 120 | #### [Non-breaking change] getStatusText renamed getReasonPhrase 121 | 122 | The function `getStatusText` has been renamed to `getReasonPhrase`. The old function is still available, but may be deprecated in a future version. To fix this simply rename instances of `getStatusText()` to `getReasonPhrase()`. The function is otherwise the same as it was before. 123 | 124 | #### [Non-breaking change] StatusCodes 125 | 126 | In http-status-codes v1, Status Codes were exported directly from the top-level module. i.e. `HttpStatus.OK`. In v2 all Status Codes live under an object called `StatusCodes`. i.e. `HttpStatus.StatusCodes.OK`. We made this change to cater to TypeScript users who prefer a dedicated value with an enum type. The previous values are still exported, but we won't continue to update them. Please migrate if you're using the old-style imports. 127 | 128 | ## Proposing a new status code 129 | 130 | If you'd like to propose a new status code, feel free to update "codes.json" with the necessary 131 | information and open a pull request. There is no need to modify source code or even this README. 132 | This is done automatically by `npm run update-codes`. 133 | 134 | In general, we try to include only codes that have an official RFC and have been approved, however 135 | exceptions can be made if the code is already in widespread use in the wild. 136 | 137 | ## Steps to build and publish 138 | 139 | ```shell 140 | npm run update-codes 141 | npm run test 142 | npm run build 143 | npm version [major | minor | patch] 144 | npm publish 145 | ``` 146 | 147 | After releasing, please add release notes via GitHub Releases. 148 | -------------------------------------------------------------------------------- /codes.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "code": 202, 4 | "phrase": "Accepted", 5 | "constant": "ACCEPTED", 6 | "comment": { 7 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.3", 8 | "description": "The request has been received but not yet acted upon. It is non-committal, meaning that there is no way in HTTP to later send an asynchronous response indicating the outcome of processing the request. It is intended for cases where another process or server handles the request, or for batch processing." 9 | } 10 | }, 11 | { 12 | "code": 502, 13 | "phrase": "Bad Gateway", 14 | "constant": "BAD_GATEWAY", 15 | "comment": { 16 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.3", 17 | "description": "This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response." 18 | } 19 | }, 20 | { 21 | "code": 400, 22 | "phrase": "Bad Request", 23 | "constant": "BAD_REQUEST", 24 | "comment": { 25 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.1", 26 | "description": "This response means that server could not understand the request due to invalid syntax." 27 | } 28 | }, 29 | { 30 | "code": 409, 31 | "phrase": "Conflict", 32 | "constant": "CONFLICT", 33 | "comment": { 34 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.8", 35 | "description": "This response is sent when a request conflicts with the current state of the server." 36 | } 37 | }, 38 | { 39 | "code": 100, 40 | "phrase": "Continue", 41 | "constant": "CONTINUE", 42 | "comment": { 43 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1", 44 | "description": "This interim response indicates that everything so far is OK and that the client should continue with the request or ignore it if it is already finished." 45 | } 46 | }, 47 | { 48 | "code": 201, 49 | "phrase": "Created", 50 | "constant": "CREATED", 51 | "comment": { 52 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.2", 53 | "description": "The request has succeeded and a new resource has been created as a result of it. This is typically the response sent after a PUT request." 54 | } 55 | }, 56 | { 57 | "code": 417, 58 | "phrase": "Expectation Failed", 59 | "constant": "EXPECTATION_FAILED", 60 | "comment": { 61 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.14", 62 | "description": "This response code means the expectation indicated by the Expect request header field can't be met by the server." 63 | } 64 | }, 65 | { 66 | "code": 424, 67 | "phrase": "Failed Dependency", 68 | "constant": "FAILED_DEPENDENCY", 69 | "comment": { 70 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.5", 71 | "description": "The request failed due to failure of a previous request." 72 | } 73 | }, 74 | { 75 | "code": 403, 76 | "phrase": "Forbidden", 77 | "constant": "FORBIDDEN", 78 | "comment": { 79 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.3", 80 | "description": "The client does not have access rights to the content, i.e. they are unauthorized, so server is rejecting to give proper response. Unlike 401, the client's identity is known to the server." 81 | } 82 | }, 83 | { 84 | "code": 504, 85 | "phrase": "Gateway Timeout", 86 | "constant": "GATEWAY_TIMEOUT", 87 | "comment": { 88 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.5", 89 | "description": "This error response is given when the server is acting as a gateway and cannot get a response in time." 90 | } 91 | }, 92 | { 93 | "code": 410, 94 | "phrase": "Gone", 95 | "constant": "GONE", 96 | "comment": { 97 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.9", 98 | "description": "This response would be sent when the requested content has been permenantly deleted from server, with no forwarding address. Clients are expected to remove their caches and links to the resource. The HTTP specification intends this status code to be used for \"limited-time, promotional services\". APIs should not feel compelled to indicate resources that have been deleted with this status code." 99 | } 100 | }, 101 | { 102 | "code": 505, 103 | "phrase": "HTTP Version Not Supported", 104 | "constant": "HTTP_VERSION_NOT_SUPPORTED", 105 | "comment": { 106 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.6", 107 | "description": "The HTTP version used in the request is not supported by the server." 108 | } 109 | }, 110 | { 111 | "code": 418, 112 | "phrase": "I'm a teapot", 113 | "constant": "IM_A_TEAPOT", 114 | "comment": { 115 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc2324#section-2.3.2", 116 | "description": "Any attempt to brew coffee with a teapot should result in the error code \"418 I'm a teapot\". The resulting entity body MAY be short and stout." 117 | } 118 | }, 119 | { 120 | "code": 419, 121 | "phrase": "Insufficient Space on Resource", 122 | "constant": "INSUFFICIENT_SPACE_ON_RESOURCE", 123 | "comment": { 124 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6", 125 | "description": "The 507 (Insufficient Storage) status code means the method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. This condition is considered to be temporary. If the request which received this status code was the result of a user action, the request MUST NOT be repeated until it is requested by a separate user action." 126 | } 127 | }, 128 | { 129 | "code": 507, 130 | "phrase": "Insufficient Storage", 131 | "constant": "INSUFFICIENT_STORAGE", 132 | "comment": { 133 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6", 134 | "description": "The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process." 135 | } 136 | }, 137 | { 138 | "code": 500, 139 | "phrase": "Internal Server Error", 140 | "constant": "INTERNAL_SERVER_ERROR", 141 | "comment": { 142 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.1", 143 | "description": "The server encountered an unexpected condition that prevented it from fulfilling the request." 144 | } 145 | }, 146 | { 147 | "code": 411, 148 | "phrase": "Length Required", 149 | "constant": "LENGTH_REQUIRED", 150 | "comment": { 151 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.10", 152 | "description": "The server rejected the request because the Content-Length header field is not defined and the server requires it." 153 | } 154 | }, 155 | { 156 | "code": 423, 157 | "phrase": "Locked", 158 | "constant": "LOCKED", 159 | "comment": { 160 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.4", 161 | "description": "The resource that is being accessed is locked." 162 | } 163 | }, 164 | { 165 | "code": 420, 166 | "phrase": "Method Failure", 167 | "constant": "METHOD_FAILURE", 168 | "isDeprecated": true, 169 | "comment": { 170 | "doc": "Official Documentation @ https://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt", 171 | "description": "A deprecated response used by the Spring Framework when a method has failed." 172 | } 173 | }, 174 | { 175 | "code": 405, 176 | "phrase": "Method Not Allowed", 177 | "constant": "METHOD_NOT_ALLOWED", 178 | "comment": { 179 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.5", 180 | "description": "The request method is known by the server but has been disabled and cannot be used. For example, an API may forbid DELETE-ing a resource. The two mandatory methods, GET and HEAD, must never be disabled and should not return this error code." 181 | } 182 | }, 183 | { 184 | "code": 301, 185 | "phrase": "Moved Permanently", 186 | "constant": "MOVED_PERMANENTLY", 187 | "comment": { 188 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.2", 189 | "description": "This response code means that URI of requested resource has been changed. Probably, new URI would be given in the response." 190 | } 191 | }, 192 | { 193 | "code": 302, 194 | "phrase": "Moved Temporarily", 195 | "constant": "MOVED_TEMPORARILY", 196 | "comment": { 197 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.3", 198 | "description": "This response code means that URI of requested resource has been changed temporarily. New changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests." 199 | } 200 | }, 201 | { 202 | "code": 207, 203 | "phrase": "Multi-Status", 204 | "constant": "MULTI_STATUS", 205 | "comment": { 206 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.2", 207 | "description": "A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate." 208 | } 209 | }, 210 | { 211 | "code": 300, 212 | "phrase": "Multiple Choices", 213 | "constant": "MULTIPLE_CHOICES", 214 | "comment": { 215 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.1", 216 | "description": "The request has more than one possible responses. User-agent or user should choose one of them. There is no standardized way to choose one of the responses." 217 | } 218 | }, 219 | { 220 | "code": 511, 221 | "phrase": "Network Authentication Required", 222 | "constant": "NETWORK_AUTHENTICATION_REQUIRED", 223 | "comment": { 224 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc6585#section-6", 225 | "description": "The 511 status code indicates that the client needs to authenticate to gain network access." 226 | } 227 | }, 228 | { 229 | "code": 204, 230 | "phrase": "No Content", 231 | "constant": "NO_CONTENT", 232 | "comment": { 233 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.5", 234 | "description": "There is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones." 235 | } 236 | }, 237 | { 238 | "code": 203, 239 | "phrase": "Non Authoritative Information", 240 | "constant": "NON_AUTHORITATIVE_INFORMATION", 241 | "comment": { 242 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.4", 243 | "description": "This response code means returned meta-information set is not exact set as available from the origin server, but collected from a local or a third party copy. Except this condition, 200 OK response should be preferred instead of this response." 244 | } 245 | }, 246 | { 247 | "code": 406, 248 | "phrase": "Not Acceptable", 249 | "constant": "NOT_ACCEPTABLE", 250 | "comment": { 251 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.6", 252 | "description": "This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content following the criteria given by the user agent." 253 | } 254 | }, 255 | { 256 | "code": 404, 257 | "phrase": "Not Found", 258 | "constant": "NOT_FOUND", 259 | "comment": { 260 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.4", 261 | "description": "The server can not find requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurence on the web." 262 | } 263 | }, 264 | { 265 | "code": 501, 266 | "phrase": "Not Implemented", 267 | "constant": "NOT_IMPLEMENTED", 268 | "comment": { 269 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.2", 270 | "description": "The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD." 271 | } 272 | }, 273 | { 274 | "code": 304, 275 | "phrase": "Not Modified", 276 | "constant": "NOT_MODIFIED", 277 | "comment": { 278 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.1", 279 | "description": "This is used for caching purposes. It is telling to client that response has not been modified. So, client can continue to use same cached version of response." 280 | } 281 | }, 282 | { 283 | "code": 200, 284 | "phrase": "OK", 285 | "constant": "OK", 286 | "comment": { 287 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.1", 288 | "description": "The request has succeeded. The meaning of a success varies depending on the HTTP method:\nGET: The resource has been fetched and is transmitted in the message body.\nHEAD: The entity headers are in the message body.\nPOST: The resource describing the result of the action is transmitted in the message body.\nTRACE: The message body contains the request message as received by the server" 289 | } 290 | }, 291 | { 292 | "code": 206, 293 | "phrase": "Partial Content", 294 | "constant": "PARTIAL_CONTENT", 295 | "comment": { 296 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7233#section-4.1", 297 | "description": "This response code is used because of range header sent by the client to separate download into multiple streams." 298 | } 299 | }, 300 | { 301 | "code": 402, 302 | "phrase": "Payment Required", 303 | "constant": "PAYMENT_REQUIRED", 304 | "comment": { 305 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.2", 306 | "description": "This response code is reserved for future use. Initial aim for creating this code was using it for digital payment systems however this is not used currently." 307 | } 308 | }, 309 | { 310 | "code": 308, 311 | "phrase": "Permanent Redirect", 312 | "constant": "PERMANENT_REDIRECT", 313 | "comment": { 314 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7538#section-3", 315 | "description": "This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request." 316 | } 317 | }, 318 | { 319 | "code": 412, 320 | "phrase": "Precondition Failed", 321 | "constant": "PRECONDITION_FAILED", 322 | "comment": { 323 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.2", 324 | "description": "The client has indicated preconditions in its headers which the server does not meet." 325 | } 326 | }, 327 | { 328 | "code": 428, 329 | "phrase": "Precondition Required", 330 | "constant": "PRECONDITION_REQUIRED", 331 | "comment": { 332 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc6585#section-3", 333 | "description": "The origin server requires the request to be conditional. Intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict." 334 | } 335 | }, 336 | { 337 | "code": 102, 338 | "phrase": "Processing", 339 | "constant": "PROCESSING", 340 | "comment": { 341 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.1", 342 | "description": "This code indicates that the server has received and is processing the request, but no response is available yet." 343 | } 344 | }, 345 | { 346 | "code": 103, 347 | "phrase": "Early Hints", 348 | "constant": "EARLY_HINTS", 349 | "isDeprecated": false, 350 | "comment": { 351 | "doc": "Official Documentation @ https://www.rfc-editor.org/rfc/rfc8297#page-3", 352 | "description": "This code indicates to the client that the server is likely to send a final response with the header fields included in the informational response." 353 | } 354 | }, 355 | { 356 | "code": 426, 357 | "phrase": "Upgrade Required", 358 | "constant": "UPGRADE_REQUIRED", 359 | "isDeprecated": false, 360 | "comment": { 361 | "doc": "Official Documentation @ https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.15", 362 | "description": "The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol." 363 | } 364 | }, 365 | { 366 | "code": 407, 367 | "phrase": "Proxy Authentication Required", 368 | "constant": "PROXY_AUTHENTICATION_REQUIRED", 369 | "comment": { 370 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.2", 371 | "description": "This is similar to 401 but authentication is needed to be done by a proxy." 372 | } 373 | }, 374 | { 375 | "code": 431, 376 | "phrase": "Request Header Fields Too Large", 377 | "constant": "REQUEST_HEADER_FIELDS_TOO_LARGE", 378 | "comment": { 379 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc6585#section-5", 380 | "description": "The server is unwilling to process the request because its header fields are too large. The request MAY be resubmitted after reducing the size of the request header fields." 381 | } 382 | }, 383 | { 384 | "code": 408, 385 | "phrase": "Request Timeout", 386 | "constant": "REQUEST_TIMEOUT", 387 | "comment": { 388 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.7", 389 | "description": "This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection. This response is used much more since some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also note that some servers merely shut down the connection without sending this message." 390 | } 391 | }, 392 | { 393 | "code": 413, 394 | "phrase": "Request Entity Too Large", 395 | "constant": "REQUEST_TOO_LONG", 396 | "comment": { 397 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.11", 398 | "description": "Request entity is larger than limits defined by server; the server might close the connection or return an Retry-After header field." 399 | } 400 | }, 401 | { 402 | "code": 414, 403 | "phrase": "Request-URI Too Long", 404 | "constant": "REQUEST_URI_TOO_LONG", 405 | "comment": { 406 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.12", 407 | "description": "The URI requested by the client is longer than the server is willing to interpret." 408 | } 409 | }, 410 | { 411 | "code": 416, 412 | "phrase": "Requested Range Not Satisfiable", 413 | "constant": "REQUESTED_RANGE_NOT_SATISFIABLE", 414 | "comment": { 415 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7233#section-4.4", 416 | "description": "The range specified by the Range header field in the request can't be fulfilled; it's possible that the range is outside the size of the target URI's data." 417 | } 418 | }, 419 | { 420 | "code": 205, 421 | "phrase": "Reset Content", 422 | "constant": "RESET_CONTENT", 423 | "comment": { 424 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.6", 425 | "description": "This response code is sent after accomplishing request to tell user agent reset document view which sent this request." 426 | } 427 | }, 428 | { 429 | "code": 303, 430 | "phrase": "See Other", 431 | "constant": "SEE_OTHER", 432 | "comment": { 433 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.4", 434 | "description": "Server sent this response to directing client to get requested resource to another URI with an GET request." 435 | } 436 | }, 437 | { 438 | "code": 503, 439 | "phrase": "Service Unavailable", 440 | "constant": "SERVICE_UNAVAILABLE", 441 | "comment": { 442 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.4", 443 | "description": "The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. Note that together with this response, a user-friendly page explaining the problem should be sent. This responses should be used for temporary conditions and the Retry-After: HTTP header should, if possible, contain the estimated time before the recovery of the service. The webmaster must also take care about the caching-related headers that are sent along with this response, as these temporary condition responses should usually not be cached." 444 | } 445 | }, 446 | { 447 | "code": 101, 448 | "phrase": "Switching Protocols", 449 | "constant": "SWITCHING_PROTOCOLS", 450 | "comment": { 451 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.2", 452 | "description": "This code is sent in response to an Upgrade request header by the client, and indicates the protocol the server is switching too." 453 | } 454 | }, 455 | { 456 | "code": 307, 457 | "phrase": "Temporary Redirect", 458 | "constant": "TEMPORARY_REDIRECT", 459 | "comment": { 460 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.7", 461 | "description": "Server sent this response to directing client to get requested resource to another URI with same method that used prior request. This has the same semantic than the 302 Found HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request." 462 | } 463 | }, 464 | { 465 | "code": 429, 466 | "phrase": "Too Many Requests", 467 | "constant": "TOO_MANY_REQUESTS", 468 | "comment": { 469 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc6585#section-4", 470 | "description": "The user has sent too many requests in a given amount of time (\"rate limiting\")." 471 | } 472 | }, 473 | { 474 | "code": 401, 475 | "phrase": "Unauthorized", 476 | "constant": "UNAUTHORIZED", 477 | "comment": { 478 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.1", 479 | "description": "Although the HTTP standard specifies \"unauthorized\", semantically this response means \"unauthenticated\". That is, the client must authenticate itself to get the requested response." 480 | } 481 | }, 482 | { 483 | "code": 451, 484 | "phrase": "Unavailable For Legal Reasons", 485 | "constant": "UNAVAILABLE_FOR_LEGAL_REASONS", 486 | "comment": { 487 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7725", 488 | "description": "The user-agent requested a resource that cannot legally be provided, such as a web page censored by a government." 489 | } 490 | }, 491 | { 492 | "code": 422, 493 | "phrase": "Unprocessable Entity", 494 | "constant": "UNPROCESSABLE_ENTITY", 495 | "comment": { 496 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.3", 497 | "description": "The request was well-formed but was unable to be followed due to semantic errors." 498 | } 499 | }, 500 | { 501 | "code": 415, 502 | "phrase": "Unsupported Media Type", 503 | "constant": "UNSUPPORTED_MEDIA_TYPE", 504 | "comment": { 505 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.13", 506 | "description": "The media format of the requested data is not supported by the server, so the server is rejecting the request." 507 | } 508 | }, 509 | { 510 | "code": 305, 511 | "phrase": "Use Proxy", 512 | "constant": "USE_PROXY", 513 | "isDeprecated": true, 514 | "comment": { 515 | "doc": "Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.6", 516 | "description": "Was defined in a previous version of the HTTP specification to indicate that a requested response must be accessed by a proxy. It has been deprecated due to security concerns regarding in-band configuration of a proxy." 517 | } 518 | }, 519 | { 520 | "code": 421, 521 | "phrase": "Misdirected Request", 522 | "constant": "MISDIRECTED_REQUEST", 523 | "isDeprecated": false, 524 | "comment": { 525 | "doc": "Official Documentation @ https://datatracker.ietf.org/doc/html/rfc7540#section-9.1.2", 526 | "description": "Defined in the specification of HTTP/2 to indicate that a server is not able to produce a response for the combination of scheme and authority that are included in the request URI." 527 | } 528 | } 529 | ] 530 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node', 4 | globals: { 5 | 'ts-jest': { 6 | tsConfig: 'tsconfig.json', 7 | }, 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "http-status-codes", 3 | "sideEffects": false, 4 | "version": "2.3.0", 5 | "description": "Constants enumerating the HTTP status codes. Based on the Java Apache HttpStatus API.", 6 | "scripts": { 7 | "update-codes": "ts-node --project ./scripts/tsconfig.json ./scripts/update-codes", 8 | "build": "./scripts/build.sh", 9 | "lint": "eslint .", 10 | "test": "jest ./src" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/prettymuchbryce/http-status-codes.git" 15 | }, 16 | "files": [ 17 | "build/", 18 | "LICENSE", 19 | "README.MD" 20 | ], 21 | "main": "./build/cjs/index.js", 22 | "module": "./build/es/index.js", 23 | "keywords": [ 24 | "node", 25 | "http", 26 | "apache", 27 | "HttpStatus", 28 | "httpclient", 29 | "status", 30 | "codes" 31 | ], 32 | "author": "Bryce Neal", 33 | "license": "MIT", 34 | "devDependencies": { 35 | "@types/fs-extra": "^9.0.1", 36 | "@types/jest": "^26.0.10", 37 | "@types/markdown-table": "^2.0.0", 38 | "@typescript-eslint/eslint-plugin": "^3.9.0", 39 | "@typescript-eslint/parser": "^3.9.1", 40 | "eslint": "^7.7.0", 41 | "eslint-config-airbnb-typescript": "^9.0.0", 42 | "eslint-plugin-import": "^2.22.0", 43 | "fs-extra": "^9.0.1", 44 | "jest": "^26.4.0", 45 | "markdown-table": "^2.0.0", 46 | "ts-jest": "^26.2.0", 47 | "ts-morph": "^7.3.0", 48 | "ts-node": "^9.0.0", 49 | "typescript": "^3.9.7" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf ./build 3 | tsc --project tsconfig-cjs.json 4 | tsc --project tsconfig-es.json 5 | -------------------------------------------------------------------------------- /scripts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "Node", 5 | "target": "es2019", 6 | "strict": true, 7 | "esModuleInterop": true, 8 | "skipLibCheck": true, 9 | "forceConsistentCasingInFileNames": true, 10 | "lib": ["es2020.string"], 11 | "resolveJsonModule": true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /scripts/update-codes.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | /** 4 | * This script should be run after modifying codes.json 5 | * It regenerates codes.ts, and updates the table in README.md 6 | * */ 7 | 8 | import fs from 'fs-extra'; 9 | 10 | import { 11 | Writers, VariableDeclarationKind, Project, StructureKind, EnumMemberStructure, OptionalKind, 12 | } from 'ts-morph'; 13 | 14 | import markdownTable from 'markdown-table'; 15 | 16 | import Codes from '../codes.json'; 17 | 18 | interface JsonCodeComment { 19 | doc: string; 20 | description: string; 21 | } 22 | 23 | interface JsonCode { 24 | code: number; 25 | phrase: string; 26 | constant: string; 27 | comment: JsonCodeComment; 28 | isDeprecated?: boolean; 29 | } 30 | 31 | const run = async () => { 32 | console.log('Updating src/codes.ts'); 33 | 34 | const project = new Project({ 35 | tsConfigFilePath: 'tsconfig.json', 36 | }); 37 | 38 | const reasonPhraseMembers: OptionalKind[] = Codes 39 | .map(({ 40 | phrase, constant, comment, isDeprecated, 41 | }: JsonCode) => { 42 | const { doc, description } = comment; 43 | const deprecatedString = isDeprecated ? '@deprecated\n' : ''; 44 | return { 45 | name: constant, 46 | value: phrase, 47 | docs: [`${deprecatedString}${doc}\n\n${description}`], 48 | }; 49 | }); 50 | 51 | const statusCodeMembers: OptionalKind[] = Codes 52 | .map(({ 53 | code, constant, comment, isDeprecated, 54 | }: JsonCode) => { 55 | const { doc, description } = comment; 56 | const deprecatedString = isDeprecated ? '@deprecated\n' : ''; 57 | return { 58 | name: constant, 59 | value: code, 60 | docs: [`${deprecatedString}${doc}\n\n${description}`], 61 | }; 62 | }).sort(({value: aValue}, {value : bValue}) => aValue - bValue); 63 | 64 | const statusCodeToReasonPhrase = Codes 65 | .reduce((acc: Record, { code, phrase }) => { 66 | (acc as Record)[`"${code.toString()}"`] = `"${phrase}"`; 67 | return acc; 68 | }, {}); 69 | 70 | const reasonPhraseToStatusCode = Codes 71 | .reduce((acc: Record, { code, phrase }) => { 72 | (acc as Record)[`"${phrase}"`] = code; 73 | return acc; 74 | }, {}); 75 | 76 | const statusCodeFile = project.createSourceFile('src/status-codes.ts', { 77 | statements: [{ 78 | kind: StructureKind.Enum, 79 | name: 'StatusCodes', 80 | isExported: true, 81 | members: statusCodeMembers, 82 | }], 83 | }, 84 | { 85 | overwrite: true, 86 | }); 87 | 88 | const reasonPhraseFile = project.createSourceFile('src/reason-phrases.ts', { 89 | statements: [ 90 | { 91 | kind: StructureKind.Enum, 92 | name: 'ReasonPhrases', 93 | isExported: true, 94 | members: reasonPhraseMembers, 95 | }, 96 | ], 97 | }, 98 | { 99 | overwrite: true, 100 | }); 101 | 102 | const utilsFile = project.createSourceFile('src/utils.ts', { 103 | statements: [{ 104 | kind: StructureKind.VariableStatement, 105 | isExported: true, 106 | declarationKind: VariableDeclarationKind.Const, 107 | declarations: [{ 108 | name: 'statusCodeToReasonPhrase', 109 | type: 'Record', 110 | initializer: Writers.object(statusCodeToReasonPhrase), 111 | }], 112 | }, 113 | { 114 | kind: StructureKind.VariableStatement, 115 | isExported: true, 116 | declarationKind: VariableDeclarationKind.Const, 117 | declarations: [{ 118 | name: 'reasonPhraseToStatusCode', 119 | type: 'Record', 120 | initializer: Writers.object(reasonPhraseToStatusCode), 121 | }], 122 | }, 123 | ], 124 | }, 125 | { 126 | overwrite: true, 127 | }); 128 | 129 | [statusCodeFile, reasonPhraseFile, utilsFile].forEach((sf) => { 130 | sf.insertStatements(0, '// Generated file. Do not edit\n'); 131 | }); 132 | 133 | await project.save(); 134 | console.log('Successfully updated codes and generated src/codes.ts'); 135 | console.log('Updating README.md table'); 136 | 137 | let readmeFile = await fs.readFile('./README.md', 'utf8'); 138 | const sortedCodes = Codes.sort((a:JsonCode, b:JsonCode) => (a.code - b.code)); 139 | 140 | const table = markdownTable([ 141 | ['Code', 'Constant', 'Reason Phrase'], 142 | ...sortedCodes.map((code: JsonCode) => [code.code.toString(), code.constant, code.phrase]), 143 | ]); 144 | 145 | const readmeRegex = /## Codes\n\n([^#]*)##/g; 146 | readmeFile = readmeFile.replace(readmeRegex, `## Codes\n\n${table}\n\n##`); 147 | 148 | fs.writeFile('./README.md', readmeFile); 149 | console.log('Successfully updated README.md table'); 150 | }; 151 | 152 | run(); 153 | -------------------------------------------------------------------------------- /src/index.test.ts: -------------------------------------------------------------------------------- 1 | import * as HttpStatusV1 from '../test/v1'; 2 | import * as HttpStatusV2 from './index'; 3 | import { 4 | getReasonPhrase, getStatusCode, ReasonPhrases, StatusCodes, 5 | } from './index'; 6 | import codes from '../codes.json'; 7 | 8 | describe('Backwards compatability with v1', () => { 9 | test('Gets codes exported by constant', () => { 10 | codes.forEach((o) => { 11 | // Only test codes that were made available in v1 12 | if ((HttpStatusV1 as any)[o.constant] !== undefined) { 13 | expect((HttpStatusV1 as any)[o.constant]).toBe(o.code); 14 | expect((HttpStatusV2 as any)[o.constant]).toBe(o.code); 15 | } 16 | }); 17 | }); 18 | 19 | test('Gets reason phrase from status code', () => { 20 | codes.forEach((o) => { 21 | // Only test codes that were made available in v1 22 | if ((HttpStatusV1 as any)[o.constant] !== undefined) { 23 | if (o.code !== 500) { 24 | expect(HttpStatusV1.getStatusText(o.code)).toBe(o.phrase); 25 | expect(HttpStatusV2.getStatusText(o.code)).toBe(o.phrase); 26 | } else { 27 | // Breaking Change. These are different. 28 | expect(HttpStatusV1.getStatusText(o.code)).toBe('Server Error'); 29 | expect(HttpStatusV2.getStatusText(o.code)).toBe(o.phrase); 30 | } 31 | } 32 | }); 33 | }); 34 | 35 | test('Gets status code from phrase', () => { 36 | codes.forEach((o) => { 37 | // Only test codes that were made available in v1 38 | if ((HttpStatusV1 as any)[o.constant] !== undefined) { 39 | if (o.code !== 500) { 40 | expect(HttpStatusV1.getStatusCode(o.phrase)).toBe(o.code); 41 | // eslint-disable-next-line import/no-named-as-default-member 42 | expect(HttpStatusV2.getStatusCode(o.phrase)).toBe(o.code); 43 | } else { 44 | // Breaking Change. These are different. 45 | expect(HttpStatusV1.getStatusCode('Server Error')).toBe(o.code); 46 | expect(HttpStatusV2.getStatusCode(o.phrase)).toBe(o.code); 47 | } 48 | } 49 | }); 50 | }); 51 | }); 52 | 53 | describe('v2', () => { 54 | test('StatusCodes', () => { 55 | // Divide by two because TypeScript enums contain both key and value 56 | // when values are Number types 57 | expect(Object.keys(StatusCodes).length / 2).toBe(codes.length); 58 | codes.forEach((o) => { 59 | expect((StatusCodes)[o.constant]).toBe(o.code as number); 60 | }); 61 | }); 62 | 63 | test('ReasonPhrases', () => { 64 | expect(Object.keys(ReasonPhrases).length).toBe(codes.length); 65 | codes.forEach((o) => { 66 | expect((ReasonPhrases)[o.constant]).toBe(o.phrase); 67 | }); 68 | }); 69 | 70 | test('getReasonPhrase', () => { 71 | codes.forEach((o) => { 72 | expect(getReasonPhrase(o.code)).toBe(o.phrase); 73 | }); 74 | }); 75 | 76 | test('getStatusCode', () => { 77 | codes.forEach((o) => { 78 | expect(getStatusCode(o.phrase)).toBe(o.code); 79 | }); 80 | }); 81 | 82 | test('getReasonPhrase nonexistent phrase', () => { 83 | expect(() => { getReasonPhrase(9999999); }).toThrowError(/Status code does not exist: 9999999/); 84 | }); 85 | 86 | test('getStatusCode nonexistent code', () => { 87 | expect(() => { getStatusCode('blah blah'); }).toThrowError(/Reason phrase does not exist: blah blah/); 88 | }); 89 | }); 90 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import legacyCodes from './legacy'; 2 | 3 | import { 4 | getStatusCode, 5 | getStatusText, 6 | } from './utils-functions'; 7 | 8 | export { 9 | getStatusCode, 10 | getReasonPhrase, 11 | getStatusText, 12 | } from './utils-functions'; 13 | 14 | export { 15 | StatusCodes, 16 | } from './status-codes'; 17 | 18 | export { 19 | ReasonPhrases, 20 | } from './reason-phrases'; 21 | 22 | export * from './legacy'; 23 | 24 | export default { 25 | ...legacyCodes, 26 | getStatusCode, 27 | getStatusText, 28 | }; 29 | -------------------------------------------------------------------------------- /src/legacy.ts: -------------------------------------------------------------------------------- 1 | // Exporting constants directly to maintain compatability with v1 2 | // These are deprecated. Please don't add any new codes here. 3 | 4 | /** 5 | * @deprecated Please use StatusCodes.ACCEPTED 6 | * 7 | * */ 8 | export const ACCEPTED = 202; 9 | /** 10 | * @deprecated Please use StatusCodes.BAD_GATEWAY 11 | * 12 | * */ 13 | export const BAD_GATEWAY = 502; 14 | /** 15 | * @deprecated Please use StatusCodes.BAD_REQUEST 16 | * 17 | * */ 18 | export const BAD_REQUEST = 400; 19 | /** 20 | * @deprecated Please use StatusCodes.CONFLICT 21 | * 22 | * */ 23 | export const CONFLICT = 409; 24 | /** 25 | * @deprecated Please use StatusCodes.CONTINUE 26 | * 27 | * */ 28 | export const CONTINUE = 100; 29 | /** 30 | * @deprecated Please use StatusCodes.CREATED 31 | * 32 | * */ 33 | export const CREATED = 201; 34 | /** 35 | * @deprecated Please use StatusCodes.EXPECTATION_FAILED 36 | * 37 | * */ 38 | export const EXPECTATION_FAILED = 417; 39 | /** 40 | * @deprecated Please use StatusCodes.FAILED_DEPENDENCY 41 | * 42 | * */ 43 | export const FAILED_DEPENDENCY = 424; 44 | /** 45 | * @deprecated Please use StatusCodes.FORBIDDEN 46 | * 47 | * */ 48 | export const FORBIDDEN = 403; 49 | /** 50 | * @deprecated Please use StatusCodes.GATEWAY_TIMEOUT 51 | * 52 | * */ 53 | export const GATEWAY_TIMEOUT = 504; 54 | /** 55 | * @deprecated Please use StatusCodes.GONE 56 | * 57 | * */ 58 | export const GONE = 410; 59 | /** 60 | * @deprecated Please use StatusCodes.HTTP_VERSION_NOT_SUPPORTED 61 | * 62 | * */ 63 | export const HTTP_VERSION_NOT_SUPPORTED = 505; 64 | /** 65 | * @deprecated Please use StatusCodes.IM_A_TEAPOT 66 | * 67 | * */ 68 | export const IM_A_TEAPOT = 418; 69 | /** 70 | * @deprecated Please use StatusCodes.INSUFFICIENT_SPACE_ON_RESOURCE 71 | * 72 | * */ 73 | export const INSUFFICIENT_SPACE_ON_RESOURCE = 419; 74 | /** 75 | * @deprecated Please use StatusCodes.INSUFFICIENT_STORAGE 76 | * 77 | * */ 78 | export const INSUFFICIENT_STORAGE = 507; 79 | /** 80 | * @deprecated Please use StatusCodes.INTERNAL_SERVER_ERROR 81 | * 82 | * */ 83 | export const INTERNAL_SERVER_ERROR = 500; 84 | /** 85 | * @deprecated Please use StatusCodes.LENGTH_REQUIRED 86 | * 87 | * */ 88 | export const LENGTH_REQUIRED = 411; 89 | /** 90 | * @deprecated Please use StatusCodes.LOCKED 91 | * 92 | * */ 93 | export const LOCKED = 423; 94 | /** 95 | * @deprecated Please use StatusCodes.METHOD_FAILURE 96 | * 97 | * */ 98 | export const METHOD_FAILURE = 420; 99 | /** 100 | * @deprecated Please use StatusCodes.METHOD_NOT_ALLOWED 101 | * 102 | * */ 103 | export const METHOD_NOT_ALLOWED = 405; 104 | /** 105 | * @deprecated Please use StatusCodes.MOVED_PERMANENTLY 106 | * 107 | * */ 108 | export const MOVED_PERMANENTLY = 301; 109 | /** 110 | * @deprecated Please use StatusCodes.MOVED_TEMPORARILY 111 | * 112 | * */ 113 | export const MOVED_TEMPORARILY = 302; 114 | /** 115 | * @deprecated Please use StatusCodes.MULTI_STATUS 116 | * 117 | * */ 118 | export const MULTI_STATUS = 207; 119 | /** 120 | * @deprecated Please use StatusCodes.MULTIPLE_CHOICES 121 | * 122 | * */ 123 | export const MULTIPLE_CHOICES = 300; 124 | /** 125 | * @deprecated Please use StatusCodes.NETWORK_AUTHENTICATION_REQUIRED 126 | * 127 | * */ 128 | export const NETWORK_AUTHENTICATION_REQUIRED = 511; 129 | /** 130 | * @deprecated Please use StatusCodes.NO_CONTENT 131 | * 132 | * */ 133 | export const NO_CONTENT = 204; 134 | /** 135 | * @deprecated Please use StatusCodes.NON_AUTHORITATIVE_INFORMATION 136 | * 137 | * */ 138 | export const NON_AUTHORITATIVE_INFORMATION = 203; 139 | /** 140 | * @deprecated Please use StatusCodes.NOT_ACCEPTABLE 141 | * 142 | * */ 143 | export const NOT_ACCEPTABLE = 406; 144 | /** 145 | * @deprecated Please use StatusCodes.NOT_FOUND 146 | * 147 | * */ 148 | export const NOT_FOUND = 404; 149 | /** 150 | * @deprecated Please use StatusCodes.NOT_IMPLEMENTED 151 | * 152 | * */ 153 | export const NOT_IMPLEMENTED = 501; 154 | /** 155 | * @deprecated Please use StatusCodes.NOT_MODIFIED 156 | * 157 | * */ 158 | export const NOT_MODIFIED = 304; 159 | /** 160 | * @deprecated Please use StatusCodes.OK 161 | * 162 | * */ 163 | export const OK = 200; 164 | /** 165 | * @deprecated Please use StatusCodes.PARTIAL_CONTENT 166 | * 167 | * */ 168 | export const PARTIAL_CONTENT = 206; 169 | /** 170 | * @deprecated Please use StatusCodes.PAYMENT_REQUIRED 171 | * 172 | * */ 173 | export const PAYMENT_REQUIRED = 402; 174 | /** 175 | * @deprecated Please use StatusCodes.PERMANENT_REDIRECT 176 | * 177 | * */ 178 | export const PERMANENT_REDIRECT = 308; 179 | /** 180 | * @deprecated Please use StatusCodes.PRECONDITION_FAILED 181 | * 182 | * */ 183 | export const PRECONDITION_FAILED = 412; 184 | /** 185 | * @deprecated Please use StatusCodes.PRECONDITION_REQUIRED 186 | * 187 | * */ 188 | export const PRECONDITION_REQUIRED = 428; 189 | /** 190 | * @deprecated Please use StatusCodes.PROCESSING 191 | * 192 | * */ 193 | export const PROCESSING = 102; 194 | /** 195 | * @deprecated Please use StatusCodes.PROXY_AUTHENTICATION_REQUIRED 196 | * 197 | * */ 198 | export const PROXY_AUTHENTICATION_REQUIRED = 407; 199 | /** 200 | * @deprecated Please use StatusCodes.REQUEST_HEADER_FIELDS_TOO_LARGE 201 | * 202 | * */ 203 | export const REQUEST_HEADER_FIELDS_TOO_LARGE = 431; 204 | /** 205 | * @deprecated Please use StatusCodes.REQUEST_TIMEOUT 206 | * 207 | * */ 208 | export const REQUEST_TIMEOUT = 408; 209 | /** 210 | * @deprecated Please use StatusCodes.REQUEST_TOO_LONG 211 | * 212 | * */ 213 | export const REQUEST_TOO_LONG = 413; 214 | /** 215 | * @deprecated Please use StatusCodes.REQUEST_URI_TOO_LONG 216 | * 217 | * */ 218 | export const REQUEST_URI_TOO_LONG = 414; 219 | /** 220 | * @deprecated Please use StatusCodes.REQUESTED_RANGE_NOT_SATISFIABLE 221 | * 222 | * */ 223 | export const REQUESTED_RANGE_NOT_SATISFIABLE = 416; 224 | /** 225 | * @deprecated Please use StatusCodes.RESET_CONTENT 226 | * 227 | * */ 228 | export const RESET_CONTENT = 205; 229 | /** 230 | * @deprecated Please use StatusCodes.SEE_OTHER 231 | * 232 | * */ 233 | export const SEE_OTHER = 303; 234 | /** 235 | * @deprecated Please use StatusCodes.SERVICE_UNAVAILABLE 236 | * 237 | * */ 238 | export const SERVICE_UNAVAILABLE = 503; 239 | /** 240 | * @deprecated Please use StatusCodes.SWITCHING_PROTOCOLS 241 | * 242 | * */ 243 | export const SWITCHING_PROTOCOLS = 101; 244 | /** 245 | * @deprecated Please use StatusCodes.TEMPORARY_REDIRECT 246 | * 247 | * */ 248 | export const TEMPORARY_REDIRECT = 307; 249 | /** 250 | * @deprecated Please use StatusCodes.TOO_MANY_REQUESTS 251 | * 252 | * */ 253 | export const TOO_MANY_REQUESTS = 429; 254 | /** 255 | * @deprecated Please use StatusCodes.UNAUTHORIZED 256 | * 257 | * */ 258 | export const UNAUTHORIZED = 401; 259 | /** 260 | * @deprecated Please use StatusCodes.UNPROCESSABLE_ENTITY 261 | * 262 | * */ 263 | export const UNPROCESSABLE_ENTITY = 422; 264 | /** 265 | * @deprecated Please use StatusCodes.UNSUPPORTED_MEDIA_TYPE 266 | * 267 | * */ 268 | export const UNSUPPORTED_MEDIA_TYPE = 415; 269 | /** 270 | * @deprecated Please use StatusCodes.USE_PROXY 271 | * 272 | * */ 273 | export const USE_PROXY = 305; 274 | 275 | export default { 276 | ACCEPTED, 277 | BAD_GATEWAY, 278 | BAD_REQUEST, 279 | CONFLICT, 280 | CONTINUE, 281 | CREATED, 282 | EXPECTATION_FAILED, 283 | FORBIDDEN, 284 | GATEWAY_TIMEOUT, 285 | GONE, 286 | HTTP_VERSION_NOT_SUPPORTED, 287 | IM_A_TEAPOT, 288 | INSUFFICIENT_SPACE_ON_RESOURCE, 289 | INSUFFICIENT_STORAGE, 290 | INTERNAL_SERVER_ERROR, 291 | LENGTH_REQUIRED, 292 | LOCKED, 293 | METHOD_FAILURE, 294 | METHOD_NOT_ALLOWED, 295 | MOVED_PERMANENTLY, 296 | MOVED_TEMPORARILY, 297 | MULTI_STATUS, 298 | MULTIPLE_CHOICES, 299 | NETWORK_AUTHENTICATION_REQUIRED, 300 | NO_CONTENT, 301 | NON_AUTHORITATIVE_INFORMATION, 302 | NOT_ACCEPTABLE, 303 | NOT_FOUND, 304 | NOT_IMPLEMENTED, 305 | NOT_MODIFIED, 306 | OK, 307 | PARTIAL_CONTENT, 308 | PAYMENT_REQUIRED, 309 | PERMANENT_REDIRECT, 310 | PRECONDITION_FAILED, 311 | PRECONDITION_REQUIRED, 312 | PROCESSING, 313 | PROXY_AUTHENTICATION_REQUIRED, 314 | REQUEST_HEADER_FIELDS_TOO_LARGE, 315 | REQUEST_TIMEOUT, 316 | REQUEST_TOO_LONG, 317 | REQUEST_URI_TOO_LONG, 318 | REQUESTED_RANGE_NOT_SATISFIABLE, 319 | RESET_CONTENT, 320 | SEE_OTHER, 321 | SERVICE_UNAVAILABLE, 322 | SWITCHING_PROTOCOLS, 323 | TEMPORARY_REDIRECT, 324 | TOO_MANY_REQUESTS, 325 | UNAUTHORIZED, 326 | UNPROCESSABLE_ENTITY, 327 | UNSUPPORTED_MEDIA_TYPE, 328 | USE_PROXY, 329 | }; 330 | -------------------------------------------------------------------------------- /src/reason-phrases.ts: -------------------------------------------------------------------------------- 1 | // Generated file. Do not edit 2 | export enum ReasonPhrases { 3 | /** 4 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.3 5 | * 6 | * The request has been received but not yet acted upon. It is non-committal, meaning that there is no way in HTTP to later send an asynchronous response indicating the outcome of processing the request. It is intended for cases where another process or server handles the request, or for batch processing. 7 | */ 8 | ACCEPTED = "Accepted", 9 | /** 10 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.3 11 | * 12 | * This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response. 13 | */ 14 | BAD_GATEWAY = "Bad Gateway", 15 | /** 16 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.1 17 | * 18 | * This response means that server could not understand the request due to invalid syntax. 19 | */ 20 | BAD_REQUEST = "Bad Request", 21 | /** 22 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.8 23 | * 24 | * This response is sent when a request conflicts with the current state of the server. 25 | */ 26 | CONFLICT = "Conflict", 27 | /** 28 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1 29 | * 30 | * This interim response indicates that everything so far is OK and that the client should continue with the request or ignore it if it is already finished. 31 | */ 32 | CONTINUE = "Continue", 33 | /** 34 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.2 35 | * 36 | * The request has succeeded and a new resource has been created as a result of it. This is typically the response sent after a PUT request. 37 | */ 38 | CREATED = "Created", 39 | /** 40 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.14 41 | * 42 | * This response code means the expectation indicated by the Expect request header field can't be met by the server. 43 | */ 44 | EXPECTATION_FAILED = "Expectation Failed", 45 | /** 46 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.5 47 | * 48 | * The request failed due to failure of a previous request. 49 | */ 50 | FAILED_DEPENDENCY = "Failed Dependency", 51 | /** 52 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.3 53 | * 54 | * The client does not have access rights to the content, i.e. they are unauthorized, so server is rejecting to give proper response. Unlike 401, the client's identity is known to the server. 55 | */ 56 | FORBIDDEN = "Forbidden", 57 | /** 58 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.5 59 | * 60 | * This error response is given when the server is acting as a gateway and cannot get a response in time. 61 | */ 62 | GATEWAY_TIMEOUT = "Gateway Timeout", 63 | /** 64 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.9 65 | * 66 | * This response would be sent when the requested content has been permenantly deleted from server, with no forwarding address. Clients are expected to remove their caches and links to the resource. The HTTP specification intends this status code to be used for "limited-time, promotional services". APIs should not feel compelled to indicate resources that have been deleted with this status code. 67 | */ 68 | GONE = "Gone", 69 | /** 70 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.6 71 | * 72 | * The HTTP version used in the request is not supported by the server. 73 | */ 74 | HTTP_VERSION_NOT_SUPPORTED = "HTTP Version Not Supported", 75 | /** 76 | * Official Documentation @ https://tools.ietf.org/html/rfc2324#section-2.3.2 77 | * 78 | * Any attempt to brew coffee with a teapot should result in the error code "418 I'm a teapot". The resulting entity body MAY be short and stout. 79 | */ 80 | IM_A_TEAPOT = "I'm a teapot", 81 | /** 82 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6 83 | * 84 | * The 507 (Insufficient Storage) status code means the method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. This condition is considered to be temporary. If the request which received this status code was the result of a user action, the request MUST NOT be repeated until it is requested by a separate user action. 85 | */ 86 | INSUFFICIENT_SPACE_ON_RESOURCE = "Insufficient Space on Resource", 87 | /** 88 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6 89 | * 90 | * The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. 91 | */ 92 | INSUFFICIENT_STORAGE = "Insufficient Storage", 93 | /** 94 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.1 95 | * 96 | * The server encountered an unexpected condition that prevented it from fulfilling the request. 97 | */ 98 | INTERNAL_SERVER_ERROR = "Internal Server Error", 99 | /** 100 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.10 101 | * 102 | * The server rejected the request because the Content-Length header field is not defined and the server requires it. 103 | */ 104 | LENGTH_REQUIRED = "Length Required", 105 | /** 106 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.4 107 | * 108 | * The resource that is being accessed is locked. 109 | */ 110 | LOCKED = "Locked", 111 | /** 112 | * @deprecated 113 | * Official Documentation @ https://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt 114 | * 115 | * A deprecated response used by the Spring Framework when a method has failed. 116 | */ 117 | METHOD_FAILURE = "Method Failure", 118 | /** 119 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.5 120 | * 121 | * The request method is known by the server but has been disabled and cannot be used. For example, an API may forbid DELETE-ing a resource. The two mandatory methods, GET and HEAD, must never be disabled and should not return this error code. 122 | */ 123 | METHOD_NOT_ALLOWED = "Method Not Allowed", 124 | /** 125 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.2 126 | * 127 | * This response code means that URI of requested resource has been changed. Probably, new URI would be given in the response. 128 | */ 129 | MOVED_PERMANENTLY = "Moved Permanently", 130 | /** 131 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.3 132 | * 133 | * This response code means that URI of requested resource has been changed temporarily. New changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests. 134 | */ 135 | MOVED_TEMPORARILY = "Moved Temporarily", 136 | /** 137 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.2 138 | * 139 | * A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate. 140 | */ 141 | MULTI_STATUS = "Multi-Status", 142 | /** 143 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.1 144 | * 145 | * The request has more than one possible responses. User-agent or user should choose one of them. There is no standardized way to choose one of the responses. 146 | */ 147 | MULTIPLE_CHOICES = "Multiple Choices", 148 | /** 149 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-6 150 | * 151 | * The 511 status code indicates that the client needs to authenticate to gain network access. 152 | */ 153 | NETWORK_AUTHENTICATION_REQUIRED = "Network Authentication Required", 154 | /** 155 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.5 156 | * 157 | * There is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones. 158 | */ 159 | NO_CONTENT = "No Content", 160 | /** 161 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.4 162 | * 163 | * This response code means returned meta-information set is not exact set as available from the origin server, but collected from a local or a third party copy. Except this condition, 200 OK response should be preferred instead of this response. 164 | */ 165 | NON_AUTHORITATIVE_INFORMATION = "Non Authoritative Information", 166 | /** 167 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.6 168 | * 169 | * This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content following the criteria given by the user agent. 170 | */ 171 | NOT_ACCEPTABLE = "Not Acceptable", 172 | /** 173 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.4 174 | * 175 | * The server can not find requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurence on the web. 176 | */ 177 | NOT_FOUND = "Not Found", 178 | /** 179 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.2 180 | * 181 | * The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD. 182 | */ 183 | NOT_IMPLEMENTED = "Not Implemented", 184 | /** 185 | * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.1 186 | * 187 | * This is used for caching purposes. It is telling to client that response has not been modified. So, client can continue to use same cached version of response. 188 | */ 189 | NOT_MODIFIED = "Not Modified", 190 | /** 191 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.1 192 | * 193 | * The request has succeeded. The meaning of a success varies depending on the HTTP method: 194 | * GET: The resource has been fetched and is transmitted in the message body. 195 | * HEAD: The entity headers are in the message body. 196 | * POST: The resource describing the result of the action is transmitted in the message body. 197 | * TRACE: The message body contains the request message as received by the server 198 | */ 199 | OK = "OK", 200 | /** 201 | * Official Documentation @ https://tools.ietf.org/html/rfc7233#section-4.1 202 | * 203 | * This response code is used because of range header sent by the client to separate download into multiple streams. 204 | */ 205 | PARTIAL_CONTENT = "Partial Content", 206 | /** 207 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.2 208 | * 209 | * This response code is reserved for future use. Initial aim for creating this code was using it for digital payment systems however this is not used currently. 210 | */ 211 | PAYMENT_REQUIRED = "Payment Required", 212 | /** 213 | * Official Documentation @ https://tools.ietf.org/html/rfc7538#section-3 214 | * 215 | * This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request. 216 | */ 217 | PERMANENT_REDIRECT = "Permanent Redirect", 218 | /** 219 | * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.2 220 | * 221 | * The client has indicated preconditions in its headers which the server does not meet. 222 | */ 223 | PRECONDITION_FAILED = "Precondition Failed", 224 | /** 225 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-3 226 | * 227 | * The origin server requires the request to be conditional. Intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict. 228 | */ 229 | PRECONDITION_REQUIRED = "Precondition Required", 230 | /** 231 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.1 232 | * 233 | * This code indicates that the server has received and is processing the request, but no response is available yet. 234 | */ 235 | PROCESSING = "Processing", 236 | /** 237 | * Official Documentation @ https://www.rfc-editor.org/rfc/rfc8297#page-3 238 | * 239 | * This code indicates to the client that the server is likely to send a final response with the header fields included in the informational response. 240 | */ 241 | EARLY_HINTS = "Early Hints", 242 | /** 243 | * Official Documentation @ https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.15 244 | * 245 | * The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. 246 | */ 247 | UPGRADE_REQUIRED = "Upgrade Required", 248 | /** 249 | * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.2 250 | * 251 | * This is similar to 401 but authentication is needed to be done by a proxy. 252 | */ 253 | PROXY_AUTHENTICATION_REQUIRED = "Proxy Authentication Required", 254 | /** 255 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-5 256 | * 257 | * The server is unwilling to process the request because its header fields are too large. The request MAY be resubmitted after reducing the size of the request header fields. 258 | */ 259 | REQUEST_HEADER_FIELDS_TOO_LARGE = "Request Header Fields Too Large", 260 | /** 261 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.7 262 | * 263 | * This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection. This response is used much more since some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also note that some servers merely shut down the connection without sending this message. 264 | */ 265 | REQUEST_TIMEOUT = "Request Timeout", 266 | /** 267 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.11 268 | * 269 | * Request entity is larger than limits defined by server; the server might close the connection or return an Retry-After header field. 270 | */ 271 | REQUEST_TOO_LONG = "Request Entity Too Large", 272 | /** 273 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.12 274 | * 275 | * The URI requested by the client is longer than the server is willing to interpret. 276 | */ 277 | REQUEST_URI_TOO_LONG = "Request-URI Too Long", 278 | /** 279 | * Official Documentation @ https://tools.ietf.org/html/rfc7233#section-4.4 280 | * 281 | * The range specified by the Range header field in the request can't be fulfilled; it's possible that the range is outside the size of the target URI's data. 282 | */ 283 | REQUESTED_RANGE_NOT_SATISFIABLE = "Requested Range Not Satisfiable", 284 | /** 285 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.6 286 | * 287 | * This response code is sent after accomplishing request to tell user agent reset document view which sent this request. 288 | */ 289 | RESET_CONTENT = "Reset Content", 290 | /** 291 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.4 292 | * 293 | * Server sent this response to directing client to get requested resource to another URI with an GET request. 294 | */ 295 | SEE_OTHER = "See Other", 296 | /** 297 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.4 298 | * 299 | * The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. Note that together with this response, a user-friendly page explaining the problem should be sent. This responses should be used for temporary conditions and the Retry-After: HTTP header should, if possible, contain the estimated time before the recovery of the service. The webmaster must also take care about the caching-related headers that are sent along with this response, as these temporary condition responses should usually not be cached. 300 | */ 301 | SERVICE_UNAVAILABLE = "Service Unavailable", 302 | /** 303 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.2 304 | * 305 | * This code is sent in response to an Upgrade request header by the client, and indicates the protocol the server is switching too. 306 | */ 307 | SWITCHING_PROTOCOLS = "Switching Protocols", 308 | /** 309 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.7 310 | * 311 | * Server sent this response to directing client to get requested resource to another URI with same method that used prior request. This has the same semantic than the 302 Found HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request. 312 | */ 313 | TEMPORARY_REDIRECT = "Temporary Redirect", 314 | /** 315 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-4 316 | * 317 | * The user has sent too many requests in a given amount of time ("rate limiting"). 318 | */ 319 | TOO_MANY_REQUESTS = "Too Many Requests", 320 | /** 321 | * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.1 322 | * 323 | * Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. 324 | */ 325 | UNAUTHORIZED = "Unauthorized", 326 | /** 327 | * Official Documentation @ https://tools.ietf.org/html/rfc7725 328 | * 329 | * The user-agent requested a resource that cannot legally be provided, such as a web page censored by a government. 330 | */ 331 | UNAVAILABLE_FOR_LEGAL_REASONS = "Unavailable For Legal Reasons", 332 | /** 333 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.3 334 | * 335 | * The request was well-formed but was unable to be followed due to semantic errors. 336 | */ 337 | UNPROCESSABLE_ENTITY = "Unprocessable Entity", 338 | /** 339 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.13 340 | * 341 | * The media format of the requested data is not supported by the server, so the server is rejecting the request. 342 | */ 343 | UNSUPPORTED_MEDIA_TYPE = "Unsupported Media Type", 344 | /** 345 | * @deprecated 346 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.6 347 | * 348 | * Was defined in a previous version of the HTTP specification to indicate that a requested response must be accessed by a proxy. It has been deprecated due to security concerns regarding in-band configuration of a proxy. 349 | */ 350 | USE_PROXY = "Use Proxy", 351 | /** 352 | * Official Documentation @ https://datatracker.ietf.org/doc/html/rfc7540#section-9.1.2 353 | * 354 | * Defined in the specification of HTTP/2 to indicate that a server is not able to produce a response for the combination of scheme and authority that are included in the request URI. 355 | */ 356 | MISDIRECTED_REQUEST = "Misdirected Request" 357 | } 358 | -------------------------------------------------------------------------------- /src/status-codes.ts: -------------------------------------------------------------------------------- 1 | // Generated file. Do not edit 2 | export enum StatusCodes { 3 | /** 4 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1 5 | * 6 | * This interim response indicates that everything so far is OK and that the client should continue with the request or ignore it if it is already finished. 7 | */ 8 | CONTINUE = 100, 9 | /** 10 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.2 11 | * 12 | * This code is sent in response to an Upgrade request header by the client, and indicates the protocol the server is switching too. 13 | */ 14 | SWITCHING_PROTOCOLS = 101, 15 | /** 16 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.1 17 | * 18 | * This code indicates that the server has received and is processing the request, but no response is available yet. 19 | */ 20 | PROCESSING = 102, 21 | /** 22 | * Official Documentation @ https://www.rfc-editor.org/rfc/rfc8297#page-3 23 | * 24 | * This code indicates to the client that the server is likely to send a final response with the header fields included in the informational response. 25 | */ 26 | EARLY_HINTS = 103, 27 | /** 28 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.1 29 | * 30 | * The request has succeeded. The meaning of a success varies depending on the HTTP method: 31 | * GET: The resource has been fetched and is transmitted in the message body. 32 | * HEAD: The entity headers are in the message body. 33 | * POST: The resource describing the result of the action is transmitted in the message body. 34 | * TRACE: The message body contains the request message as received by the server 35 | */ 36 | OK = 200, 37 | /** 38 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.2 39 | * 40 | * The request has succeeded and a new resource has been created as a result of it. This is typically the response sent after a PUT request. 41 | */ 42 | CREATED = 201, 43 | /** 44 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.3 45 | * 46 | * The request has been received but not yet acted upon. It is non-committal, meaning that there is no way in HTTP to later send an asynchronous response indicating the outcome of processing the request. It is intended for cases where another process or server handles the request, or for batch processing. 47 | */ 48 | ACCEPTED = 202, 49 | /** 50 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.4 51 | * 52 | * This response code means returned meta-information set is not exact set as available from the origin server, but collected from a local or a third party copy. Except this condition, 200 OK response should be preferred instead of this response. 53 | */ 54 | NON_AUTHORITATIVE_INFORMATION = 203, 55 | /** 56 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.5 57 | * 58 | * There is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones. 59 | */ 60 | NO_CONTENT = 204, 61 | /** 62 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.6 63 | * 64 | * This response code is sent after accomplishing request to tell user agent reset document view which sent this request. 65 | */ 66 | RESET_CONTENT = 205, 67 | /** 68 | * Official Documentation @ https://tools.ietf.org/html/rfc7233#section-4.1 69 | * 70 | * This response code is used because of range header sent by the client to separate download into multiple streams. 71 | */ 72 | PARTIAL_CONTENT = 206, 73 | /** 74 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.2 75 | * 76 | * A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate. 77 | */ 78 | MULTI_STATUS = 207, 79 | /** 80 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.1 81 | * 82 | * The request has more than one possible responses. User-agent or user should choose one of them. There is no standardized way to choose one of the responses. 83 | */ 84 | MULTIPLE_CHOICES = 300, 85 | /** 86 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.2 87 | * 88 | * This response code means that URI of requested resource has been changed. Probably, new URI would be given in the response. 89 | */ 90 | MOVED_PERMANENTLY = 301, 91 | /** 92 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.3 93 | * 94 | * This response code means that URI of requested resource has been changed temporarily. New changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests. 95 | */ 96 | MOVED_TEMPORARILY = 302, 97 | /** 98 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.4 99 | * 100 | * Server sent this response to directing client to get requested resource to another URI with an GET request. 101 | */ 102 | SEE_OTHER = 303, 103 | /** 104 | * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.1 105 | * 106 | * This is used for caching purposes. It is telling to client that response has not been modified. So, client can continue to use same cached version of response. 107 | */ 108 | NOT_MODIFIED = 304, 109 | /** 110 | * @deprecated 111 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.6 112 | * 113 | * Was defined in a previous version of the HTTP specification to indicate that a requested response must be accessed by a proxy. It has been deprecated due to security concerns regarding in-band configuration of a proxy. 114 | */ 115 | USE_PROXY = 305, 116 | /** 117 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.7 118 | * 119 | * Server sent this response to directing client to get requested resource to another URI with same method that used prior request. This has the same semantic than the 302 Found HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request. 120 | */ 121 | TEMPORARY_REDIRECT = 307, 122 | /** 123 | * Official Documentation @ https://tools.ietf.org/html/rfc7538#section-3 124 | * 125 | * This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request. 126 | */ 127 | PERMANENT_REDIRECT = 308, 128 | /** 129 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.1 130 | * 131 | * This response means that server could not understand the request due to invalid syntax. 132 | */ 133 | BAD_REQUEST = 400, 134 | /** 135 | * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.1 136 | * 137 | * Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. 138 | */ 139 | UNAUTHORIZED = 401, 140 | /** 141 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.2 142 | * 143 | * This response code is reserved for future use. Initial aim for creating this code was using it for digital payment systems however this is not used currently. 144 | */ 145 | PAYMENT_REQUIRED = 402, 146 | /** 147 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.3 148 | * 149 | * The client does not have access rights to the content, i.e. they are unauthorized, so server is rejecting to give proper response. Unlike 401, the client's identity is known to the server. 150 | */ 151 | FORBIDDEN = 403, 152 | /** 153 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.4 154 | * 155 | * The server can not find requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurence on the web. 156 | */ 157 | NOT_FOUND = 404, 158 | /** 159 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.5 160 | * 161 | * The request method is known by the server but has been disabled and cannot be used. For example, an API may forbid DELETE-ing a resource. The two mandatory methods, GET and HEAD, must never be disabled and should not return this error code. 162 | */ 163 | METHOD_NOT_ALLOWED = 405, 164 | /** 165 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.6 166 | * 167 | * This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content following the criteria given by the user agent. 168 | */ 169 | NOT_ACCEPTABLE = 406, 170 | /** 171 | * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.2 172 | * 173 | * This is similar to 401 but authentication is needed to be done by a proxy. 174 | */ 175 | PROXY_AUTHENTICATION_REQUIRED = 407, 176 | /** 177 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.7 178 | * 179 | * This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection. This response is used much more since some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also note that some servers merely shut down the connection without sending this message. 180 | */ 181 | REQUEST_TIMEOUT = 408, 182 | /** 183 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.8 184 | * 185 | * This response is sent when a request conflicts with the current state of the server. 186 | */ 187 | CONFLICT = 409, 188 | /** 189 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.9 190 | * 191 | * This response would be sent when the requested content has been permenantly deleted from server, with no forwarding address. Clients are expected to remove their caches and links to the resource. The HTTP specification intends this status code to be used for "limited-time, promotional services". APIs should not feel compelled to indicate resources that have been deleted with this status code. 192 | */ 193 | GONE = 410, 194 | /** 195 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.10 196 | * 197 | * The server rejected the request because the Content-Length header field is not defined and the server requires it. 198 | */ 199 | LENGTH_REQUIRED = 411, 200 | /** 201 | * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.2 202 | * 203 | * The client has indicated preconditions in its headers which the server does not meet. 204 | */ 205 | PRECONDITION_FAILED = 412, 206 | /** 207 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.11 208 | * 209 | * Request entity is larger than limits defined by server; the server might close the connection or return an Retry-After header field. 210 | */ 211 | REQUEST_TOO_LONG = 413, 212 | /** 213 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.12 214 | * 215 | * The URI requested by the client is longer than the server is willing to interpret. 216 | */ 217 | REQUEST_URI_TOO_LONG = 414, 218 | /** 219 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.13 220 | * 221 | * The media format of the requested data is not supported by the server, so the server is rejecting the request. 222 | */ 223 | UNSUPPORTED_MEDIA_TYPE = 415, 224 | /** 225 | * Official Documentation @ https://tools.ietf.org/html/rfc7233#section-4.4 226 | * 227 | * The range specified by the Range header field in the request can't be fulfilled; it's possible that the range is outside the size of the target URI's data. 228 | */ 229 | REQUESTED_RANGE_NOT_SATISFIABLE = 416, 230 | /** 231 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.14 232 | * 233 | * This response code means the expectation indicated by the Expect request header field can't be met by the server. 234 | */ 235 | EXPECTATION_FAILED = 417, 236 | /** 237 | * Official Documentation @ https://tools.ietf.org/html/rfc2324#section-2.3.2 238 | * 239 | * Any attempt to brew coffee with a teapot should result in the error code "418 I'm a teapot". The resulting entity body MAY be short and stout. 240 | */ 241 | IM_A_TEAPOT = 418, 242 | /** 243 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6 244 | * 245 | * The 507 (Insufficient Storage) status code means the method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. This condition is considered to be temporary. If the request which received this status code was the result of a user action, the request MUST NOT be repeated until it is requested by a separate user action. 246 | */ 247 | INSUFFICIENT_SPACE_ON_RESOURCE = 419, 248 | /** 249 | * @deprecated 250 | * Official Documentation @ https://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt 251 | * 252 | * A deprecated response used by the Spring Framework when a method has failed. 253 | */ 254 | METHOD_FAILURE = 420, 255 | /** 256 | * Official Documentation @ https://datatracker.ietf.org/doc/html/rfc7540#section-9.1.2 257 | * 258 | * Defined in the specification of HTTP/2 to indicate that a server is not able to produce a response for the combination of scheme and authority that are included in the request URI. 259 | */ 260 | MISDIRECTED_REQUEST = 421, 261 | /** 262 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.3 263 | * 264 | * The request was well-formed but was unable to be followed due to semantic errors. 265 | */ 266 | UNPROCESSABLE_ENTITY = 422, 267 | /** 268 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.4 269 | * 270 | * The resource that is being accessed is locked. 271 | */ 272 | LOCKED = 423, 273 | /** 274 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.5 275 | * 276 | * The request failed due to failure of a previous request. 277 | */ 278 | FAILED_DEPENDENCY = 424, 279 | /** 280 | * Official Documentation @ https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.15 281 | * 282 | * The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. 283 | */ 284 | UPGRADE_REQUIRED = 426, 285 | /** 286 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-3 287 | * 288 | * The origin server requires the request to be conditional. Intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict. 289 | */ 290 | PRECONDITION_REQUIRED = 428, 291 | /** 292 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-4 293 | * 294 | * The user has sent too many requests in a given amount of time ("rate limiting"). 295 | */ 296 | TOO_MANY_REQUESTS = 429, 297 | /** 298 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-5 299 | * 300 | * The server is unwilling to process the request because its header fields are too large. The request MAY be resubmitted after reducing the size of the request header fields. 301 | */ 302 | REQUEST_HEADER_FIELDS_TOO_LARGE = 431, 303 | /** 304 | * Official Documentation @ https://tools.ietf.org/html/rfc7725 305 | * 306 | * The user-agent requested a resource that cannot legally be provided, such as a web page censored by a government. 307 | */ 308 | UNAVAILABLE_FOR_LEGAL_REASONS = 451, 309 | /** 310 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.1 311 | * 312 | * The server encountered an unexpected condition that prevented it from fulfilling the request. 313 | */ 314 | INTERNAL_SERVER_ERROR = 500, 315 | /** 316 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.2 317 | * 318 | * The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD. 319 | */ 320 | NOT_IMPLEMENTED = 501, 321 | /** 322 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.3 323 | * 324 | * This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response. 325 | */ 326 | BAD_GATEWAY = 502, 327 | /** 328 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.4 329 | * 330 | * The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. Note that together with this response, a user-friendly page explaining the problem should be sent. This responses should be used for temporary conditions and the Retry-After: HTTP header should, if possible, contain the estimated time before the recovery of the service. The webmaster must also take care about the caching-related headers that are sent along with this response, as these temporary condition responses should usually not be cached. 331 | */ 332 | SERVICE_UNAVAILABLE = 503, 333 | /** 334 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.5 335 | * 336 | * This error response is given when the server is acting as a gateway and cannot get a response in time. 337 | */ 338 | GATEWAY_TIMEOUT = 504, 339 | /** 340 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.6 341 | * 342 | * The HTTP version used in the request is not supported by the server. 343 | */ 344 | HTTP_VERSION_NOT_SUPPORTED = 505, 345 | /** 346 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6 347 | * 348 | * The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. 349 | */ 350 | INSUFFICIENT_STORAGE = 507, 351 | /** 352 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-6 353 | * 354 | * The 511 status code indicates that the client needs to authenticate to gain network access. 355 | */ 356 | NETWORK_AUTHENTICATION_REQUIRED = 511 357 | } 358 | -------------------------------------------------------------------------------- /src/utils-functions.ts: -------------------------------------------------------------------------------- 1 | import { 2 | statusCodeToReasonPhrase, 3 | reasonPhraseToStatusCode, 4 | } from './utils'; 5 | 6 | /** 7 | * Returns the reason phrase for the given status code. 8 | * If the given status code does not exist, an error is thrown. 9 | * 10 | * @param {number|string} statusCode The HTTP status code 11 | * @returns {string} The associated reason phrase (e.g. "Bad Request", "OK") 12 | * */ 13 | export function getReasonPhrase(statusCode: (number | string)): (string) { 14 | const result = statusCodeToReasonPhrase[statusCode.toString()]; 15 | if (!result) { 16 | throw new Error(`Status code does not exist: ${statusCode}`); 17 | } 18 | return result; 19 | } 20 | 21 | /** 22 | * Returns the status code for the given reason phrase. 23 | * If the given reason phrase does not exist, undefined is returned. 24 | * 25 | * @param {string} reasonPhrase The HTTP reason phrase (e.g. "Bad Request", "OK") 26 | * @returns {string} The associated status code 27 | * */ 28 | export function getStatusCode(reasonPhrase: string): (number) { 29 | const result = reasonPhraseToStatusCode[reasonPhrase]; 30 | if (!result) { 31 | throw new Error(`Reason phrase does not exist: ${reasonPhrase}`); 32 | } 33 | return result; 34 | } 35 | 36 | /** 37 | * @deprecated 38 | * 39 | * Returns the reason phrase for the given status code. 40 | * If the given status code does not exist, undefined is returned. 41 | * 42 | * Deprecated in favor of getReasonPhrase 43 | * 44 | * @param {number|string} statusCode The HTTP status code 45 | * @returns {string|undefined} The associated reason phrase (e.g. "Bad Request", "OK") 46 | * */ 47 | export const getStatusText = getReasonPhrase; 48 | -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | // Generated file. Do not edit 2 | export const statusCodeToReasonPhrase: Record = { 3 | "202": "Accepted", 4 | "502": "Bad Gateway", 5 | "400": "Bad Request", 6 | "409": "Conflict", 7 | "100": "Continue", 8 | "201": "Created", 9 | "417": "Expectation Failed", 10 | "424": "Failed Dependency", 11 | "403": "Forbidden", 12 | "504": "Gateway Timeout", 13 | "410": "Gone", 14 | "505": "HTTP Version Not Supported", 15 | "418": "I'm a teapot", 16 | "419": "Insufficient Space on Resource", 17 | "507": "Insufficient Storage", 18 | "500": "Internal Server Error", 19 | "411": "Length Required", 20 | "423": "Locked", 21 | "420": "Method Failure", 22 | "405": "Method Not Allowed", 23 | "301": "Moved Permanently", 24 | "302": "Moved Temporarily", 25 | "207": "Multi-Status", 26 | "300": "Multiple Choices", 27 | "511": "Network Authentication Required", 28 | "204": "No Content", 29 | "203": "Non Authoritative Information", 30 | "406": "Not Acceptable", 31 | "404": "Not Found", 32 | "501": "Not Implemented", 33 | "304": "Not Modified", 34 | "200": "OK", 35 | "206": "Partial Content", 36 | "402": "Payment Required", 37 | "308": "Permanent Redirect", 38 | "412": "Precondition Failed", 39 | "428": "Precondition Required", 40 | "102": "Processing", 41 | "103": "Early Hints", 42 | "426": "Upgrade Required", 43 | "407": "Proxy Authentication Required", 44 | "431": "Request Header Fields Too Large", 45 | "408": "Request Timeout", 46 | "413": "Request Entity Too Large", 47 | "414": "Request-URI Too Long", 48 | "416": "Requested Range Not Satisfiable", 49 | "205": "Reset Content", 50 | "303": "See Other", 51 | "503": "Service Unavailable", 52 | "101": "Switching Protocols", 53 | "307": "Temporary Redirect", 54 | "429": "Too Many Requests", 55 | "401": "Unauthorized", 56 | "451": "Unavailable For Legal Reasons", 57 | "422": "Unprocessable Entity", 58 | "415": "Unsupported Media Type", 59 | "305": "Use Proxy", 60 | "421": "Misdirected Request" 61 | }; 62 | export const reasonPhraseToStatusCode: Record = { 63 | "Accepted": 202, 64 | "Bad Gateway": 502, 65 | "Bad Request": 400, 66 | "Conflict": 409, 67 | "Continue": 100, 68 | "Created": 201, 69 | "Expectation Failed": 417, 70 | "Failed Dependency": 424, 71 | "Forbidden": 403, 72 | "Gateway Timeout": 504, 73 | "Gone": 410, 74 | "HTTP Version Not Supported": 505, 75 | "I'm a teapot": 418, 76 | "Insufficient Space on Resource": 419, 77 | "Insufficient Storage": 507, 78 | "Internal Server Error": 500, 79 | "Length Required": 411, 80 | "Locked": 423, 81 | "Method Failure": 420, 82 | "Method Not Allowed": 405, 83 | "Moved Permanently": 301, 84 | "Moved Temporarily": 302, 85 | "Multi-Status": 207, 86 | "Multiple Choices": 300, 87 | "Network Authentication Required": 511, 88 | "No Content": 204, 89 | "Non Authoritative Information": 203, 90 | "Not Acceptable": 406, 91 | "Not Found": 404, 92 | "Not Implemented": 501, 93 | "Not Modified": 304, 94 | "OK": 200, 95 | "Partial Content": 206, 96 | "Payment Required": 402, 97 | "Permanent Redirect": 308, 98 | "Precondition Failed": 412, 99 | "Precondition Required": 428, 100 | "Processing": 102, 101 | "Early Hints": 103, 102 | "Upgrade Required": 426, 103 | "Proxy Authentication Required": 407, 104 | "Request Header Fields Too Large": 431, 105 | "Request Timeout": 408, 106 | "Request Entity Too Large": 413, 107 | "Request-URI Too Long": 414, 108 | "Requested Range Not Satisfiable": 416, 109 | "Reset Content": 205, 110 | "See Other": 303, 111 | "Service Unavailable": 503, 112 | "Switching Protocols": 101, 113 | "Temporary Redirect": 307, 114 | "Too Many Requests": 429, 115 | "Unauthorized": 401, 116 | "Unavailable For Legal Reasons": 451, 117 | "Unprocessable Entity": 422, 118 | "Unsupported Media Type": 415, 119 | "Use Proxy": 305, 120 | "Misdirected Request": 421 121 | }; 122 | -------------------------------------------------------------------------------- /test/v1.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.3 3 | * 4 | * The request has been received but not yet acted upon. It is non-committal, meaning that there is no way in HTTP to later send an asynchronous response indicating the outcome of processing the request. It is intended for cases where another process or server handles the request, or for batch processing. 5 | */ 6 | export declare const ACCEPTED = 202; 7 | /** 8 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.3 9 | * 10 | * This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response. 11 | */ 12 | export declare const BAD_GATEWAY = 502; 13 | /** 14 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.1 15 | * 16 | * This response means that server could not understand the request due to invalid syntax. 17 | */ 18 | export declare const BAD_REQUEST = 400; 19 | /** 20 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.8 21 | * 22 | * This response is sent when a request conflicts with the current state of the server. 23 | */ 24 | export declare const CONFLICT = 409; 25 | /** 26 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1 27 | * 28 | * This interim response indicates that everything so far is OK and that the client should continue with the request or ignore it if it is already finished. 29 | */ 30 | export declare const CONTINUE = 100; 31 | /** 32 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.2 33 | * 34 | * The request has succeeded and a new resource has been created as a result of it. This is typically the response sent after a PUT request. 35 | */ 36 | export declare const CREATED = 201; 37 | /** 38 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.14 39 | * 40 | * This response code means the expectation indicated by the Expect request header field can't be met by the server. 41 | */ 42 | export declare const EXPECTATION_FAILED = 417; 43 | /** 44 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.5 45 | * 46 | * The request failed due to failure of a previous request. 47 | */ 48 | export declare const FAILED_DEPENDENCY = 424; 49 | /** 50 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.3 51 | * 52 | * The client does not have access rights to the content, i.e. they are unauthorized, so server is rejecting to give proper response. Unlike 401, the client's identity is known to the server. 53 | */ 54 | export declare const FORBIDDEN = 403; 55 | /** 56 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.5 57 | * 58 | * This error response is given when the server is acting as a gateway and cannot get a response in time. 59 | */ 60 | export declare const GATEWAY_TIMEOUT = 504; 61 | /** 62 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.9 63 | * 64 | * This response would be sent when the requested content has been permenantly deleted from server, with no forwarding address. Clients are expected to remove their caches and links to the resource. The HTTP specification intends this status code to be used for "limited-time, promotional services". APIs should not feel compelled to indicate resources that have been deleted with this status code. 65 | */ 66 | export declare const GONE = 410; 67 | /** 68 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.6 69 | * 70 | * The HTTP version used in the request is not supported by the server. 71 | */ 72 | export declare const HTTP_VERSION_NOT_SUPPORTED = 505; 73 | /** 74 | * Official Documentation @ https://tools.ietf.org/html/rfc2324#section-2.3.2 75 | * 76 | * Any attempt to brew coffee with a teapot should result in the error code "418 I'm a teapot". The resulting entity body MAY be short and stout. 77 | */ 78 | export declare const IM_A_TEAPOT = 418; 79 | /** 80 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6 81 | * 82 | * The 507 (Insufficient Storage) status code means the method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. This condition is considered to be temporary. If the request which received this status code was the result of a user action, the request MUST NOT be repeated until it is requested by a separate user action. 83 | */ 84 | export declare const INSUFFICIENT_SPACE_ON_RESOURCE = 419; 85 | /** 86 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6 87 | * 88 | * The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. 89 | */ 90 | export declare const INSUFFICIENT_STORAGE = 507; 91 | /** 92 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.1 93 | * 94 | * The server has encountered a situation it doesn't know how to handle. 95 | */ 96 | export declare const INTERNAL_SERVER_ERROR = 500; 97 | /** 98 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.10 99 | * 100 | * Server rejected the request because the Content-Length header field is not defined and the server requires it. 101 | */ 102 | export declare const LENGTH_REQUIRED = 411; 103 | /** 104 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.4 105 | * 106 | * The resource that is being accessed is locked. 107 | */ 108 | export declare const LOCKED = 423; 109 | /** 110 | * Official Documentation @ https://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt 111 | * 112 | * A deprecated response used by the Spring Framework when a method has failed. 113 | */ 114 | export declare const METHOD_FAILURE = 420; 115 | /** 116 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.5 117 | * 118 | * The request method is known by the server but has been disabled and cannot be used. For example, an API may forbid DELETE-ing a resource. The two mandatory methods, GET and HEAD, must never be disabled and should not return this error code. 119 | */ 120 | export declare const METHOD_NOT_ALLOWED = 405; 121 | /** 122 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.2 123 | * 124 | * This response code means that URI of requested resource has been changed. Probably, new URI would be given in the response. 125 | */ 126 | export declare const MOVED_PERMANENTLY = 301; 127 | /** 128 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.3 129 | * 130 | * This response code means that URI of requested resource has been changed temporarily. New changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests. 131 | */ 132 | export declare const MOVED_TEMPORARILY = 302; 133 | /** 134 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.2 135 | * 136 | * A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate. 137 | */ 138 | export declare const MULTI_STATUS = 207; 139 | /** 140 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.1 141 | * 142 | * The request has more than one possible responses. User-agent or user should choose one of them. There is no standardized way to choose one of the responses. 143 | */ 144 | export declare const MULTIPLE_CHOICES = 300; 145 | /** 146 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-6 147 | * 148 | * The 511 status code indicates that the client needs to authenticate to gain network access. 149 | */ 150 | export declare const NETWORK_AUTHENTICATION_REQUIRED = 511; 151 | /** 152 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.5 153 | * 154 | * There is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones. 155 | */ 156 | export declare const NO_CONTENT = 204; 157 | /** 158 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.4 159 | * 160 | * This response code means returned meta-information set is not exact set as available from the origin server, but collected from a local or a third party copy. Except this condition, 200 OK response should be preferred instead of this response. 161 | */ 162 | export declare const NON_AUTHORITATIVE_INFORMATION = 203; 163 | /** 164 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.6 165 | * 166 | * This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content following the criteria given by the user agent. 167 | */ 168 | export declare const NOT_ACCEPTABLE = 406; 169 | /** 170 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.4 171 | * 172 | * The server can not find requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurence on the web. 173 | */ 174 | export declare const NOT_FOUND = 404; 175 | /** 176 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.2 177 | * 178 | * The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD. 179 | */ 180 | export declare const NOT_IMPLEMENTED = 501; 181 | /** 182 | * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.1 183 | * 184 | * This is used for caching purposes. It is telling to client that response has not been modified. So, client can continue to use same cached version of response. 185 | */ 186 | export declare const NOT_MODIFIED = 304; 187 | /** 188 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.1 189 | * 190 | * The request has succeeded. The meaning of a success varies depending on the HTTP method: 191 | */ 192 | export declare const OK = 200; 193 | /** 194 | * Official Documentation @ https://tools.ietf.org/html/rfc7233#section-4.1 195 | * 196 | * This response code is used because of range header sent by the client to separate download into multiple streams. 197 | */ 198 | export declare const PARTIAL_CONTENT = 206; 199 | /** 200 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.2 201 | * 202 | * This response code is reserved for future use. Initial aim for creating this code was using it for digital payment systems however this is not used currently. 203 | */ 204 | export declare const PAYMENT_REQUIRED = 402; 205 | /** 206 | * Official Documentation @ https://tools.ietf.org/html/rfc7538#section-3 207 | * 208 | * This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request. 209 | */ 210 | export declare const PERMANENT_REDIRECT = 308; 211 | /** 212 | * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.2 213 | * 214 | * The client has indicated preconditions in its headers which the server does not meet. 215 | */ 216 | export declare const PRECONDITION_FAILED = 412; 217 | /** 218 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-3 219 | * 220 | * The origin server requires the request to be conditional. Intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict. 221 | */ 222 | export declare const PRECONDITION_REQUIRED = 428; 223 | /** 224 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.1 225 | * 226 | * This code indicates that the server has received and is processing the request, but no response is available yet. 227 | */ 228 | export declare const PROCESSING = 102; 229 | /** 230 | * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.2 231 | * 232 | * This is similar to 401 but authentication is needed to be done by a proxy. 233 | */ 234 | export declare const PROXY_AUTHENTICATION_REQUIRED = 407; 235 | /** 236 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-5 237 | * 238 | * The server is unwilling to process the request because its header fields are too large. The request MAY be resubmitted after reducing the size of the request header fields. 239 | */ 240 | export declare const REQUEST_HEADER_FIELDS_TOO_LARGE = 431; 241 | /** 242 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.7 243 | * 244 | * This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection. This response is used much more since some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also note that some servers merely shut down the connection without sending this message. 245 | */ 246 | export declare const REQUEST_TIMEOUT = 408; 247 | /** 248 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.11 249 | * 250 | * Request entity is larger than limits defined by server; the server might close the connection or return an Retry-After header field. 251 | */ 252 | export declare const REQUEST_TOO_LONG = 413; 253 | /** 254 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.12 255 | * 256 | * The URI requested by the client is longer than the server is willing to interpret. 257 | */ 258 | export declare const REQUEST_URI_TOO_LONG = 414; 259 | /** 260 | * Official Documentation @ https://tools.ietf.org/html/rfc7233#section-4.4 261 | * 262 | * The range specified by the Range header field in the request can't be fulfilled; it's possible that the range is outside the size of the target URI's data. 263 | */ 264 | export declare const REQUESTED_RANGE_NOT_SATISFIABLE = 416; 265 | /** 266 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.6 267 | * 268 | * This response code is sent after accomplishing request to tell user agent reset document view which sent this request. 269 | */ 270 | export declare const RESET_CONTENT = 205; 271 | /** 272 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.4 273 | * 274 | * Server sent this response to directing client to get requested resource to another URI with an GET request. 275 | */ 276 | export declare const SEE_OTHER = 303; 277 | /** 278 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.4 279 | * 280 | * The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. Note that together with this response, a user-friendly page explaining the problem should be sent. This responses should be used for temporary conditions and the Retry-After: HTTP header should, if possible, contain the estimated time before the recovery of the service. The webmaster must also take care about the caching-related headers that are sent along with this response, as these temporary condition responses should usually not be cached. 281 | */ 282 | export declare const SERVICE_UNAVAILABLE = 503; 283 | /** 284 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.2 285 | * 286 | * This code is sent in response to an Upgrade request header by the client, and indicates the protocol the server is switching too. 287 | */ 288 | export declare const SWITCHING_PROTOCOLS = 101; 289 | /** 290 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.7 291 | * 292 | * Server sent this response to directing client to get requested resource to another URI with same method that used prior request. This has the same semantic than the 302 Found HTTP response code, with the exception that the user agent must not change the HTTP method used: if a POST was used in the first request, a POST must be used in the second request. 293 | */ 294 | export declare const TEMPORARY_REDIRECT = 307; 295 | /** 296 | * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-4 297 | * 298 | * The user has sent too many requests in a given amount of time ("rate limiting"). 299 | */ 300 | export declare const TOO_MANY_REQUESTS = 429; 301 | /** 302 | * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.1 303 | * 304 | * Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. 305 | */ 306 | export declare const UNAUTHORIZED = 401; 307 | /** 308 | * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.3 309 | * 310 | * The request was well-formed but was unable to be followed due to semantic errors. 311 | */ 312 | export declare const UNPROCESSABLE_ENTITY = 422; 313 | /** 314 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.13 315 | * 316 | * The media format of the requested data is not supported by the server, so the server is rejecting the request. 317 | */ 318 | export declare const UNSUPPORTED_MEDIA_TYPE = 415; 319 | /** 320 | * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.4.6 321 | * 322 | * Was defined in a previous version of the HTTP specification to indicate that a requested response must be accessed by a proxy. It has been deprecated due to security concerns regarding in-band configuration of a proxy. 323 | */ 324 | export declare const USE_PROXY = 305; 325 | /** 326 | * Convert the numeric status code to its appropriate title. 327 | * @param statusCode One of the available status codes in this package 328 | * @returns {String} The associated title of the passed status code 329 | * @throws {Error} The status code does not exist 330 | */ 331 | export declare function getStatusText(statusCode: number): string; 332 | 333 | /** 334 | * Convert the status reason phrase to its appropriate numeric value 335 | * @param reasonPhrase One of the available reason phrases in this package 336 | * @returns {Number} The associated status code of the passed reason phrase 337 | * @throws {Error} The reason phrase does not exist 338 | */ 339 | export declare function getStatusCode(reasonPhrase: string): number; 340 | -------------------------------------------------------------------------------- /test/v1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Constants enumerating the HTTP status codes. 3 | * 4 | * All status codes defined in RFC1945 (HTTP/1.0, RFC2616 (HTTP/1.1), 5 | * RFC2518 (WebDAV), RFC6585 (Additional HTTP Status Codes), and 6 | * RFC7538 (Permanent Redirect) are supported. 7 | * 8 | * Based on the org.apache.commons.httpclient.HttpStatus Java API. 9 | * 10 | * Ported by Bryce Neal. 11 | */ 12 | 13 | var statusCodes = {}; 14 | 15 | statusCodes[exports.ACCEPTED = 202] = "Accepted"; 16 | statusCodes[exports.BAD_GATEWAY = 502] = "Bad Gateway"; 17 | statusCodes[exports.BAD_REQUEST = 400] = "Bad Request"; 18 | statusCodes[exports.CONFLICT = 409] = "Conflict"; 19 | statusCodes[exports.CONTINUE = 100] = "Continue"; 20 | statusCodes[exports.CREATED = 201] = "Created"; 21 | statusCodes[exports.EXPECTATION_FAILED = 417] = "Expectation Failed"; 22 | statusCodes[exports.FAILED_DEPENDENCY = 424] = "Failed Dependency"; 23 | statusCodes[exports.FORBIDDEN = 403] = "Forbidden"; 24 | statusCodes[exports.GATEWAY_TIMEOUT = 504] = "Gateway Timeout"; 25 | statusCodes[exports.GONE = 410] = "Gone"; 26 | statusCodes[exports.HTTP_VERSION_NOT_SUPPORTED = 505] = "HTTP Version Not Supported"; 27 | statusCodes[exports.IM_A_TEAPOT = 418] = "I'm a teapot"; 28 | statusCodes[exports.INSUFFICIENT_SPACE_ON_RESOURCE = 419] = "Insufficient Space on Resource"; 29 | statusCodes[exports.INSUFFICIENT_STORAGE = 507] = "Insufficient Storage"; 30 | statusCodes[exports.INTERNAL_SERVER_ERROR = 500] = "Server Error"; 31 | statusCodes[exports.LENGTH_REQUIRED = 411] = "Length Required"; 32 | statusCodes[exports.LOCKED = 423] = "Locked"; 33 | statusCodes[exports.METHOD_FAILURE = 420] = "Method Failure"; 34 | statusCodes[exports.METHOD_NOT_ALLOWED = 405] = "Method Not Allowed"; 35 | statusCodes[exports.MOVED_PERMANENTLY = 301] = "Moved Permanently"; 36 | statusCodes[exports.MOVED_TEMPORARILY = 302] = "Moved Temporarily"; 37 | statusCodes[exports.MULTI_STATUS = 207] = "Multi-Status"; 38 | statusCodes[exports.MULTIPLE_CHOICES = 300] = "Multiple Choices"; 39 | statusCodes[exports.NETWORK_AUTHENTICATION_REQUIRED = 511] = "Network Authentication Required"; 40 | statusCodes[exports.NO_CONTENT = 204] = "No Content"; 41 | statusCodes[exports.NON_AUTHORITATIVE_INFORMATION = 203] = "Non Authoritative Information"; 42 | statusCodes[exports.NOT_ACCEPTABLE = 406] = "Not Acceptable"; 43 | statusCodes[exports.NOT_FOUND = 404] = "Not Found"; 44 | statusCodes[exports.NOT_IMPLEMENTED = 501] = "Not Implemented"; 45 | statusCodes[exports.NOT_MODIFIED = 304] = "Not Modified"; 46 | statusCodes[exports.OK = 200] = "OK"; 47 | statusCodes[exports.PARTIAL_CONTENT = 206] = "Partial Content"; 48 | statusCodes[exports.PAYMENT_REQUIRED = 402] = "Payment Required"; 49 | statusCodes[exports.PERMANENT_REDIRECT = 308] = "Permanent Redirect"; 50 | statusCodes[exports.PRECONDITION_FAILED = 412] = "Precondition Failed"; 51 | statusCodes[exports.PRECONDITION_REQUIRED = 428] = "Precondition Required"; 52 | statusCodes[exports.PROCESSING = 102] = "Processing"; 53 | statusCodes[exports.PROXY_AUTHENTICATION_REQUIRED = 407] = "Proxy Authentication Required"; 54 | statusCodes[exports.REQUEST_HEADER_FIELDS_TOO_LARGE = 431] = "Request Header Fields Too Large"; 55 | statusCodes[exports.REQUEST_TIMEOUT = 408] = "Request Timeout"; 56 | statusCodes[exports.REQUEST_TOO_LONG = 413] = "Request Entity Too Large"; 57 | statusCodes[exports.REQUEST_URI_TOO_LONG = 414] = "Request-URI Too Long"; 58 | statusCodes[exports.REQUESTED_RANGE_NOT_SATISFIABLE = 416] = "Requested Range Not Satisfiable"; 59 | statusCodes[exports.RESET_CONTENT = 205] = "Reset Content"; 60 | statusCodes[exports.SEE_OTHER = 303] = "See Other"; 61 | statusCodes[exports.SERVICE_UNAVAILABLE = 503] = "Service Unavailable"; 62 | statusCodes[exports.SWITCHING_PROTOCOLS = 101] = "Switching Protocols"; 63 | statusCodes[exports.TEMPORARY_REDIRECT = 307] = "Temporary Redirect"; 64 | statusCodes[exports.TOO_MANY_REQUESTS = 429] = "Too Many Requests"; 65 | statusCodes[exports.UNAUTHORIZED = 401] = "Unauthorized"; 66 | statusCodes[exports.UNPROCESSABLE_ENTITY = 422] = "Unprocessable Entity"; 67 | statusCodes[exports.UNSUPPORTED_MEDIA_TYPE = 415] = "Unsupported Media Type"; 68 | statusCodes[exports.USE_PROXY = 305] = "Use Proxy"; 69 | 70 | exports.getStatusText = function(statusCode) { 71 | if (statusCodes.hasOwnProperty(statusCode)) { 72 | return statusCodes[statusCode]; 73 | } else { 74 | throw new Error("Status code does not exist: " + statusCode); 75 | } 76 | }; 77 | 78 | exports.getStatusCode = function(reasonPhrase) { 79 | for (key in statusCodes) { 80 | if (statusCodes[key] === reasonPhrase) { 81 | return parseInt(key, 10); 82 | } 83 | } 84 | throw new Error("Reason phrase does not exist: " + reasonPhrase); 85 | }; 86 | -------------------------------------------------------------------------------- /tsconfig-cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "outDir": "./build/cjs/", 5 | "resolveJsonModule": false 6 | }, 7 | "extends": "./tsconfig.json" 8 | } 9 | -------------------------------------------------------------------------------- /tsconfig-es.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "resolveJsonModule": false, 4 | "outDir": "./build/es/" 5 | }, 6 | "extends": "./tsconfig.json" 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": ["./**/*.ts", "./**/*.js"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "es6", 5 | "strict": true, 6 | "esModuleInterop": true, 7 | "declaration": true, 8 | "skipLibCheck": true, 9 | "forceConsistentCasingInFileNames": true, 10 | "resolveJsonModule": true, 11 | "moduleResolution": "node" 12 | }, 13 | "include": ["./src/index.ts"] 14 | } 15 | --------------------------------------------------------------------------------