aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-11-23 10:45:42 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-12-03 10:15:49 +0100
commitd4132d3f56b392a2e4e632db59e6644e4851228e (patch)
treebe903734aa9ce3d669c40656a0f81bd3e9c7978c /shared
parent4a54a93941d1c095bf249331df799c51e39c3774 (diff)
downloadPeerTube-d4132d3f56b392a2e4e632db59e6644e4851228e.tar.gz
PeerTube-d4132d3f56b392a2e4e632db59e6644e4851228e.tar.zst
PeerTube-d4132d3f56b392a2e4e632db59e6644e4851228e.zip
more explicit error messages for file uploads
Diffstat (limited to 'shared')
-rw-r--r--shared/core-utils/miscs/http-error-codes.ts419
-rw-r--r--shared/core-utils/miscs/index.ts1
2 files changed, 420 insertions, 0 deletions
diff --git a/shared/core-utils/miscs/http-error-codes.ts b/shared/core-utils/miscs/http-error-codes.ts
new file mode 100644
index 000000000..6dfe73c2e
--- /dev/null
+++ b/shared/core-utils/miscs/http-error-codes.ts
@@ -0,0 +1,419 @@
1/**
2 * Hypertext Transfer Protocol (HTTP) response status codes.
3 * @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
4 */
5export enum HttpStatusCode {
6
7 /**
8 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.2.1
9 *
10 * The server has received the request headers and the client should proceed to send the request body
11 * (in the case of a request for which a body needs to be sent; for example, a POST request).
12 * Sending a large request body to a server after a request has been rejected for inappropriate headers would be inefficient.
13 * To have a server check the request's headers, a client must send Expect: 100-continue as a header in its initial request
14 * and receive a 100 Continue status code in response before sending the body. The response 417 Expectation Failed indicates
15 * the request should not be continued.
16 */
17 CONTINUE_100 = 100,
18
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 /**
27 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.1
28 *
29 * Standard response for successful HTTP requests. The actual response will depend on the request method used:
30 * GET: The resource has been fetched and is transmitted in the message body.
31 * HEAD: The entity headers are in the message body.
32 * POST: The resource describing the result of the action is transmitted in the message body.
33 * TRACE: The message body contains the request message as received by the server
34 */
35 OK_200 = 200,
36
37 /**
38 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.2
39 *
40 * The request has been fulfilled, resulting in the creation of a new resource, typically after a PUT.
41 */
42 CREATED_201 = 201,
43
44 /**
45 * The request has been accepted for processing, but the processing has not been completed.
46 * The request might or might not be eventually acted upon, and may be disallowed when processing occurs.
47 */
48 ACCEPTED_202 = 202,
49
50 /**
51 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.4
52 *
53 * SINCE HTTP/1.1
54 * The server is a transforming proxy that received a 200 OK from its origin,
55 * but is returning a modified version of the origin's response.
56 */
57 NON_AUTHORITATIVE_INFORMATION_203 = 203,
58
59 /**
60 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.3.5
61 *
62 * There is no content to send for this request, but the headers may be useful.
63 * The user-agent may update its cached headers for this resource with the new ones.
64 */
65 NO_CONTENT_204 = 204,
66
67 /**
68 * The server successfully processed the request, but is not returning any content.
69 * Unlike a 204 response, this response requires that the requester reset the document view.
70 */
71 RESET_CONTENT_205 = 205,
72
73 /**
74 * The server is delivering only part of the resource (byte serving) due to a range header sent by the client.
75 * The range header is used by HTTP clients to enable resuming of interrupted downloads,
76 * or split a download into multiple simultaneous streams.
77 */
78 PARTIAL_CONTENT_206 = 206,
79
80 /**
81 * The message body that follows is an XML message and can contain a number of separate response codes,
82 * depending on how many sub-requests were made.
83 */
84 MULTI_STATUS_207 = 207,
85
86 /**
87 * The server has fulfilled a request for the resource,
88 * and the response is a representation of the result of one or more instance-manipulations applied to the current instance.
89 */
90 IM_USED_226 = 226,
91
92 /**
93 * Indicates multiple options for the resource from which the client may choose (via agent-driven content negotiation).
94 * For example, this code could be used to present multiple video format options,
95 * to list files with different filename extensions, or to suggest word-sense disambiguation.
96 */
97 MULTIPLE_CHOICES_300 = 300,
98
99 /**
100 * This and all future requests should be directed to the given URI.
101 */
102 MOVED_PERMANENTLY_301 = 301,
103
104 /**
105 * This is an example of industry practice contradicting the standard.
106 * The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect
107 * (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302
108 * with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307
109 * to distinguish between the two behaviours. However, some Web applications and frameworks
110 * use the 302 status code as if it were the 303.
111 */
112 FOUND_302 = 302,
113
114 /**
115 * SINCE HTTP/1.1
116 * The response to the request can be found under another URI using a GET method.
117 * When received in response to a POST (or PUT/DELETE), the client should presume that
118 * the server has received the data and should issue a redirect with a separate GET message.
119 */
120 SEE_OTHER_303 = 303,
121
122 /**
123 * Official Documentation @ https://tools.ietf.org/html/rfc7232#section-4.1
124 *
125 * Indicates that the resource has not been modified since the version specified by the request headers
126 * `If-Modified-Since` or `If-None-Match`.
127 * In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy.
128 */
129 NOT_MODIFIED_304 = 304,
130
131 /**
132 * @deprecated
133 * SINCE HTTP/1.1
134 * The requested resource is available only through a proxy, the address for which is provided in the response.
135 * Many HTTP clients (such as Mozilla and Internet Explorer) do not correctly handle responses with this status
136 * code, primarily for security reasons.
137 */
138 USE_PROXY_305 = 305,
139
140 /**
141 * No longer used. Originally meant "Subsequent requests should use the specified proxy."
142 */
143 SWITCH_PROXY_306 = 306,
144
145 /**
146 * SINCE HTTP/1.1
147 * In this case, the request should be repeated with another URI; however, future requests should still use the original URI.
148 * In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the
149 * original request.
150 * For example, a POST request should be repeated using another POST request.
151 */
152 TEMPORARY_REDIRECT_307 = 307,
153
154 /**
155 * The request and all future requests should be repeated using another URI.
156 * 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change.
157 * So, for example, submitting a form to a permanently redirected resource may continue smoothly.
158 */
159 PERMANENT_REDIRECT_308 = 308,
160
161 /**
162 * The server cannot or will not process the request due to an apparent client error
163 * (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing).
164 */
165 BAD_REQUEST_400 = 400,
166
167 /**
168 * Official Documentation @ https://tools.ietf.org/html/rfc7235#section-3.1
169 *
170 * Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet
171 * been provided. The response must include a `WWW-Authenticate` header field containing a challenge applicable to the
172 * requested resource. See Basic access authentication and Digest access authentication. 401 semantically means
173 * "unauthenticated",i.e. the user does not have the necessary credentials.
174 */
175 UNAUTHORIZED_401 = 401,
176
177 /**
178 * Reserved for future use. The original intention was that this code might be used as part of some form of digital
179 * cash or micro payment scheme, but that has not happened, and this code is not usually used.
180 * Google Developers API uses this status if a particular developer has exceeded the daily limit on requests.
181 */
182 PAYMENT_REQUIRED_402 = 402,
183
184 /**
185 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.3
186 *
187 * The client does not have access rights to the content, i.e. they are unauthorized, so server is rejecting to
188 * give proper response. Unlike 401, the client's identity is known to the server.
189 */
190 FORBIDDEN_403 = 403,
191
192 /**
193 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.6.2
194 *
195 * The requested resource could not be found but may be available in the future.
196 * Subsequent requests by the client are permissible.
197 */
198 NOT_FOUND_404 = 404,
199
200 /**
201 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.5
202 *
203 * A request method is not supported for the requested resource;
204 * 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.
205 */
206 METHOD_NOT_ALLOWED_405 = 405,
207
208 /**
209 * The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.
210 */
211 NOT_ACCEPTABLE_406 = 406,
212
213 /**
214 * The client must first authenticate itself with the proxy.
215 */
216 PROXY_AUTHENTICATION_REQUIRED_407 = 407,
217
218 /**
219 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.7
220 *
221 * This response is sent on an idle connection by some servers, even without any previous request by the client.
222 * It means that the server would like to shut down this unused connection. This response is used much more since
223 * some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also
224 * note that some servers merely shut down the connection without sending this message.
225 */
226 REQUEST_TIMEOUT_408 = 408,
227
228 /**
229 * Indicates that the request could not be processed because of conflict in the request,
230 * such as an edit conflict between multiple simultaneous updates.
231 */
232 CONFLICT_409 = 409,
233
234 /**
235 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.9
236 *
237 * Indicates that the resource requested is no longer available and will not be available again.
238 * This should be used when a resource has been intentionally removed and the resource should be purged.
239 * Upon receiving a 410 status code, the client should not request the resource in the future.
240 * Clients such as search engines should remove the resource from their indices.
241 * Most use cases do not require clients and search engines to purge the resource, and a "404 Not Found" may be used instead.
242 */
243 GONE_410 = 410,
244
245 /**
246 * The request did not specify the length of its content, which is required by the requested resource.
247 */
248 LENGTH_REQUIRED_411 = 411,
249
250 /**
251 * The server does not meet one of the preconditions that the requester put on the request.
252 */
253 PRECONDITION_FAILED_412 = 412,
254
255 /**
256 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.11
257 *
258 * The request is larger than the server is willing or able to process ; the server might close the connection
259 * or return an Retry-After header field.
260 * Previously called "Request Entity Too Large".
261 */
262 PAYLOAD_TOO_LARGE_413 = 413,
263
264 /**
265 * The URI provided was too long for the server to process. Often the result of too much data being encoded as a
266 * query-string of a GET request, in which case it should be converted to a POST request.
267 * Called "Request-URI Too Long" previously.
268 */
269 URI_TOO_LONG_414 = 414,
270
271 /**
272 * Official Documentation @ https://tools.ietf.org/html/rfc7231#section-6.5.13
273 *
274 * The request entity has a media type which the server or resource does not support.
275 * For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.
276 */
277 UNSUPPORTED_MEDIA_TYPE_415 = 415,
278
279 /**
280 * The client has asked for a portion of the file (byte serving), but the server cannot supply that portion.
281 * For example, if the client asked for a part of the file that lies beyond the end of the file.
282 * Called "Requested Range Not Satisfiable" previously.
283 */
284 RANGE_NOT_SATISFIABLE_416 = 416,
285
286 /**
287 * The server cannot meet the requirements of the Expect request-header field.
288 */
289 EXPECTATION_FAILED_417 = 417,
290
291 /**
292 * This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol,
293 * and is not expected to be implemented by actual HTTP servers. The RFC specifies this code should be returned by
294 * teapots requested to brew coffee. This HTTP status is used as an Easter egg in some websites, including Google.com.
295 */
296 I_AM_A_TEAPOT_418 = 418,
297
298 /**
299 * The request was directed at a server that is not able to produce a response (for example because a connection reuse).
300 */
301 MISDIRECTED_REQUEST_421 = 421,
302
303 /**
304 * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.3
305 *
306 * The request was well-formed but was unable to be followed due to semantic errors.
307 */
308 UNPROCESSABLE_ENTITY_422 = 422,
309
310 /**
311 * The resource that is being accessed is locked.
312 */
313 LOCKED_423 = 423,
314
315 /**
316 * The request failed due to failure of a previous request (e.g., a PROPPATCH).
317 */
318 FAILED_DEPENDENCY_424 = 424,
319
320 /**
321 * The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.
322 */
323 UPGRADE_REQUIRED_426 = 426,
324
325 /**
326 * The origin server requires the request to be conditional.
327 * Intended to prevent "the 'lost update' problem, where a client
328 * GETs a resource's state, modifies it, and PUTs it back to the server,
329 * when meanwhile a third party has modified the state on the server, leading to a conflict."
330 */
331 PRECONDITION_REQUIRED_428 = 428,
332
333 /**
334 * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-4
335 *
336 * The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes.
337 */
338 TOO_MANY_REQUESTS_429 = 429,
339
340 /**
341 * Official Documentation @ https://tools.ietf.org/html/rfc6585#section-5
342 *
343 * The server is unwilling to process the request because either an individual header field,
344 * or all the header fields collectively, are too large.
345 */
346 REQUEST_HEADER_FIELDS_TOO_LARGE_431 = 431,
347
348 /**
349 * Official Documentation @ https://tools.ietf.org/html/rfc7725
350 *
351 * A server operator has received a legal demand to deny access to a resource or to a set of resources
352 * that includes the requested resource. The code 451 was chosen as a reference to the novel Fahrenheit 451.
353 */
354 UNAVAILABLE_FOR_LEGAL_REASONS_451 = 451,
355
356 /**
357 * A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
358 */
359 INTERNAL_SERVER_ERROR_500 = 500,
360
361 /**
362 * The server either does not recognize the request method, or it lacks the ability to fulfill the request.
363 * Usually this implies future availability (e.g., a new feature of a web-service API).
364 */
365 NOT_IMPLEMENTED_501 = 501,
366
367 /**
368 * The server was acting as a gateway or proxy and received an invalid response from the upstream server.
369 */
370 BAD_GATEWAY_502 = 502,
371
372 /**
373 * The server is currently unavailable (because it is overloaded or down for maintenance).
374 * Generally, this is a temporary state.
375 */
376 SERVICE_UNAVAILABLE_503 = 503,
377
378 /**
379 * The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
380 */
381 GATEWAY_TIMEOUT_504 = 504,
382
383 /**
384 * The server does not support the HTTP protocol version used in the request
385 */
386 HTTP_VERSION_NOT_SUPPORTED_505 = 505,
387
388 /**
389 * Transparent content negotiation for the request results in a circular reference.
390 */
391 VARIANT_ALSO_NEGOTIATES_506 = 506,
392
393 /**
394 * Official Documentation @ https://tools.ietf.org/html/rfc2518#section-10.6
395 *
396 * The 507 (Insufficient Storage) status code means the method could not be performed on the resource because the
397 * server is unable to store the representation needed to successfully complete the request. This condition is
398 * considered to be temporary. If the request which received this status code was the result of a user action,
399 * the request MUST NOT be repeated until it is requested by a separate user action.
400 */
401 INSUFFICIENT_STORAGE_507 = 507,
402
403 /**
404 * The server detected an infinite loop while processing the request.
405 */
406 LOOP_DETECTED_508 = 508,
407
408 /**
409 * Further extensions to the request are required for the server to fulfill it.
410 */
411 NOT_EXTENDED_510 = 510,
412
413 /**
414 * The client needs to authenticate to gain network access.
415 * Intended for use by intercepting proxies used to control access to the network (e.g., "captive portals" used
416 * to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot).
417 */
418 NETWORK_AUTHENTICATION_REQUIRED_511 = 511
419}
diff --git a/shared/core-utils/miscs/index.ts b/shared/core-utils/miscs/index.ts
index afd147f24..898fd4791 100644
--- a/shared/core-utils/miscs/index.ts
+++ b/shared/core-utils/miscs/index.ts
@@ -1,3 +1,4 @@
1export * from './date' 1export * from './date'
2export * from './miscs' 2export * from './miscs'
3export * from './types' 3export * from './types'
4export * from './http-error-codes'