http-error-codes.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /**
  2. * Hypertext Transfer Protocol (HTTP) response status codes.
  3. * @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
  4. *
  5. * WebDAV and other codes useless with regards to PeerTube are not listed.
  6. */
  7. export enum HttpStatusCode {
  8. /**
  9. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1
  10. *
  11. * The server has received the request headers and the client should proceed to send the request body
  12. * (in the case of a request for which a body needs to be sent; for example, a POST request).
  13. * Sending a large request body to a server after a request has been rejected for inappropriate headers would be inefficient.
  14. * To have a server check the request's headers, a client must send Expect: 100-continue as a header in its initial request
  15. * and receive a 100 Continue status code in response before sending the body. The response 417 Expectation Failed indicates
  16. * the request should not be continued.
  17. */
  18. CONTINUE_100 = 100,
  19. /**
  20. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.2
  21. *
  22. * This code is sent in response to an Upgrade request header by the client, and indicates the protocol the server is switching too.
  23. */
  24. SWITCHING_PROTOCOLS_101 = 101,
  25. /**
  26. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.1
  27. *
  28. * Standard response for successful HTTP requests. The actual response will depend on the request method used:
  29. * GET: The resource has been fetched and is transmitted in the message body.
  30. * HEAD: The entity headers are in the message body.
  31. * POST: The resource describing the result of the action is transmitted in the message body.
  32. * TRACE: The message body contains the request message as received by the server
  33. */
  34. OK_200 = 200,
  35. /**
  36. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.2
  37. *
  38. * The request has been fulfilled, resulting in the creation of a new resource, typically after a PUT.
  39. */
  40. CREATED_201 = 201,
  41. /**
  42. * The request has been accepted for processing, but the processing has not been completed.
  43. * The request might or might not be eventually acted upon, and may be disallowed when processing occurs.
  44. */
  45. ACCEPTED_202 = 202,
  46. /**
  47. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.5
  48. *
  49. * There is no content to send for this request, but the headers may be useful.
  50. * The user-agent may update its cached headers for this resource with the new ones.
  51. */
  52. NO_CONTENT_204 = 204,
  53. /**
  54. * The server successfully processed the request, but is not returning any content.
  55. * Unlike a 204 response, this response requires that the requester reset the document view.
  56. */
  57. RESET_CONTENT_205 = 205,
  58. /**
  59. * The server is delivering only part of the resource (byte serving) due to a range header sent by the client.
  60. * The range header is used by HTTP clients to enable resuming of interrupted downloads,
  61. * or split a download into multiple simultaneous streams.
  62. */
  63. PARTIAL_CONTENT_206 = 206,
  64. /**
  65. * Indicates multiple options for the resource from which the client may choose (via agent-driven content negotiation).
  66. * For example, this code could be used to present multiple video format options,
  67. * to list files with different filename extensions, or to suggest word-sense disambiguation.
  68. */
  69. MULTIPLE_CHOICES_300 = 300,
  70. /**
  71. * This and all future requests should be directed to the given URI.
  72. */
  73. MOVED_PERMANENTLY_301 = 301,
  74. /**
  75. * This is an example of industry practice contradicting the standard.
  76. * The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect
  77. * (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302
  78. * with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307
  79. * to distinguish between the two behaviours. However, some Web applications and frameworks
  80. * use the 302 status code as if it were the 303.
  81. */
  82. FOUND_302 = 302,
  83. /**
  84. * SINCE HTTP/1.1
  85. * The response to the request can be found under another URI using a GET method.
  86. * When received in response to a POST (or PUT/DELETE), the client should presume that
  87. * the server has received the data and should issue a redirect with a separate GET message.
  88. */
  89. SEE_OTHER_303 = 303,
  90. /**
  91. * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.1
  92. *
  93. * Indicates that the resource has not been modified since the version specified by the request headers
  94. * `If-Modified-Since` or `If-None-Match`.
  95. * In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy.
  96. */
  97. NOT_MODIFIED_304 = 304,
  98. /**
  99. * SINCE HTTP/1.1
  100. * In this case, the request should be repeated with another URI; however, future requests should still use the original URI.
  101. * In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the
  102. * original request.
  103. * For example, a POST request should be repeated using another POST request.
  104. */
  105. TEMPORARY_REDIRECT_307 = 307,
  106. /**
  107. * The request and all future requests should be repeated using another URI.
  108. * 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change.
  109. * So, for example, submitting a form to a permanently redirected resource may continue smoothly.
  110. */
  111. PERMANENT_REDIRECT_308 = 308,
  112. /**
  113. * The server cannot or will not process the request due to an apparent client error
  114. * (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).
  115. */
  116. BAD_REQUEST_400 = 400,
  117. /**
  118. * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.1
  119. *
  120. * Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet
  121. * been provided. The response must include a `WWW-Authenticate` header field containing a challenge applicable to the
  122. * requested resource. See Basic access authentication and Digest access authentication. 401 semantically means
  123. * "unauthenticated",i.e. the user does not have the necessary credentials.
  124. */
  125. UNAUTHORIZED_401 = 401,
  126. /**
  127. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.2
  128. *
  129. * Reserved for future use. The original intention was that this code might be used as part of some form of digital
  130. * cash or micro payment scheme, but that has not happened, and this code is not usually used.
  131. * Google Developers API uses this status if a particular developer has exceeded the daily limit on requests.
  132. */
  133. PAYMENT_REQUIRED_402 = 402,
  134. /**
  135. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.3
  136. *
  137. * The client does not have access rights to the content, i.e. they are unauthorized, so server is rejecting to
  138. * give proper response. Unlike 401, the client's identity is known to the server.
  139. */
  140. FORBIDDEN_403 = 403,
  141. /**
  142. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.2
  143. *
  144. * The requested resource could not be found but may be available in the future.
  145. * Subsequent requests by the client are permissible.
  146. */
  147. NOT_FOUND_404 = 404,
  148. /**
  149. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.5
  150. *
  151. * A request method is not supported for the requested resource;
  152. * for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.
  153. */
  154. METHOD_NOT_ALLOWED_405 = 405,
  155. /**
  156. * The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.
  157. */
  158. NOT_ACCEPTABLE_406 = 406,
  159. /**
  160. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.7
  161. *
  162. * This response is sent on an idle connection by some servers, even without any previous request by the client.
  163. * It means that the server would like to shut down this unused connection. This response is used much more since
  164. * some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also
  165. * note that some servers merely shut down the connection without sending this message.
  166. *
  167. * @
  168. */
  169. REQUEST_TIMEOUT_408 = 408,
  170. /**
  171. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.8
  172. *
  173. * Indicates that the request could not be processed because of conflict in the request,
  174. * such as an edit conflict between multiple simultaneous updates.
  175. *
  176. * @see HttpStatusCode.UNPROCESSABLE_ENTITY_422 to denote a disabled feature
  177. */
  178. CONFLICT_409 = 409,
  179. /**
  180. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.9
  181. *
  182. * Indicates that the resource requested is no longer available and will not be available again.
  183. * This should be used when a resource has been intentionally removed and the resource should be purged.
  184. * Upon receiving a 410 status code, the client should not request the resource in the future.
  185. * Clients such as search engines should remove the resource from their indices.
  186. * Most use cases do not require clients and search engines to purge the resource, and a "404 Not Found" may be used instead.
  187. */
  188. GONE_410 = 410,
  189. /**
  190. * The request did not specify the length of its content, which is required by the requested resource.
  191. */
  192. LENGTH_REQUIRED_411 = 411,
  193. /**
  194. * The server does not meet one of the preconditions that the requester put on the request.
  195. */
  196. PRECONDITION_FAILED_412 = 412,
  197. /**
  198. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.11
  199. *
  200. * The request is larger than the server is willing or able to process ; the server might close the connection
  201. * or return an Retry-After header field.
  202. * Previously called "Request Entity Too Large".
  203. */
  204. PAYLOAD_TOO_LARGE_413 = 413,
  205. /**
  206. * The URI provided was too long for the server to process. Often the result of too much data being encoded as a
  207. * query-string of a GET request, in which case it should be converted to a POST request.
  208. * Called "Request-URI Too Long" previously.
  209. */
  210. URI_TOO_LONG_414 = 414,
  211. /**
  212. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.13
  213. *
  214. * The request entity has a media type which the server or resource does not support.
  215. * For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.
  216. */
  217. UNSUPPORTED_MEDIA_TYPE_415 = 415,
  218. /**
  219. * The client has asked for a portion of the file (byte serving), but the server cannot supply that portion.
  220. * For example, if the client asked for a part of the file that lies beyond the end of the file.
  221. * Called "Requested Range Not Satisfiable" previously.
  222. */
  223. RANGE_NOT_SATISFIABLE_416 = 416,
  224. /**
  225. * The server cannot meet the requirements of the `Expect` request-header field.
  226. */
  227. EXPECTATION_FAILED_417 = 417,
  228. /**
  229. * Official Documentation @ https://tools.ietf.org/html/rfc2324
  230. *
  231. * This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol,
  232. * and is not expected to be implemented by actual HTTP servers. The RFC specifies this code should be returned by
  233. * teapots requested to brew coffee. This HTTP status is used as an Easter egg in some websites, including PeerTube instances ;-).
  234. */
  235. I_AM_A_TEAPOT_418 = 418,
  236. /**
  237. * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.3
  238. *
  239. * The request was well-formed but was unable to be followed due to semantic errors.
  240. * The server understands the content type of the request entity (hence a 415 (Unsupported Media Type) status code is inappropriate),
  241. * and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process
  242. * the contained instructions. For example, this error condition may occur if an JSON request body contains well-formed (i.e.,
  243. * syntactically correct), but semantically erroneous, JSON instructions.
  244. *
  245. * Can also be used to denote disabled features (akin to disabled syntax).
  246. *
  247. * @see HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 if the `Content-Type` was not supported.
  248. * @see HttpStatusCode.BAD_REQUEST_400 if the request was not parsable (broken JSON, XML)
  249. */
  250. UNPROCESSABLE_ENTITY_422 = 422,
  251. /**
  252. * Official Documentation @ https://tools.ietf.org/html/rfc4918#section-11.3
  253. *
  254. * The resource that is being accessed is locked. WebDAV-specific but used by some HTTP services.
  255. *
  256. * @deprecated use `If-Match` / `If-None-Match` instead
  257. * @see {@link https://evertpot.com/http/423-locked}
  258. */
  259. LOCKED_423 = 423,
  260. /**
  261. * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-4
  262. *
  263. * The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes.
  264. */
  265. TOO_MANY_REQUESTS_429 = 429,
  266. /**
  267. * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-5
  268. *
  269. * The server is unwilling to process the request because either an individual header field,
  270. * or all the header fields collectively, are too large.
  271. */
  272. REQUEST_HEADER_FIELDS_TOO_LARGE_431 = 431,
  273. /**
  274. * Official Documentation @ https://tools.ietf.org/html/rfc7725
  275. *
  276. * A server operator has received a legal demand to deny access to a resource or to a set of resources
  277. * that includes the requested resource. The code 451 was chosen as a reference to the novel Fahrenheit 451.
  278. */
  279. UNAVAILABLE_FOR_LEGAL_REASONS_451 = 451,
  280. /**
  281. * A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
  282. */
  283. INTERNAL_SERVER_ERROR_500 = 500,
  284. /**
  285. * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.2
  286. *
  287. * The server either does not recognize the request method, or it lacks the ability to fulfill the request.
  288. * Usually this implies future availability (e.g., a new feature of a web-service API).
  289. */
  290. NOT_IMPLEMENTED_501 = 501,
  291. /**
  292. * The server was acting as a gateway or proxy and received an invalid response from the upstream server.
  293. */
  294. BAD_GATEWAY_502 = 502,
  295. /**
  296. * The server is currently unavailable (because it is overloaded or down for maintenance).
  297. * Generally, this is a temporary state.
  298. */
  299. SERVICE_UNAVAILABLE_503 = 503,
  300. /**
  301. * The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
  302. */
  303. GATEWAY_TIMEOUT_504 = 504,
  304. /**
  305. * The server does not support the HTTP protocol version used in the request
  306. */
  307. HTTP_VERSION_NOT_SUPPORTED_505 = 505,
  308. /**
  309. * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6
  310. *
  311. * The 507 (Insufficient Storage) status code means the method could not be performed on the resource because the
  312. * server is unable to store the representation needed to successfully complete the request. This condition is
  313. * considered to be temporary. If the request which received this status code was the result of a user action,
  314. * the request MUST NOT be repeated until it is requested by a separate user action.
  315. *
  316. * @see HttpStatusCode.PAYLOAD_TOO_LARGE_413 for quota errors
  317. */
  318. INSUFFICIENT_STORAGE_507 = 507,
  319. }