Dashboard  2
Lot's of data
Loading...
Searching...
No Matches
speak_on_correct_status.ts
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** area-rattrapage
4** File description:
5** speak_on_correct_status.js
6*/
7
8import { Response } from "express";
9
10export namespace SpeakOnCorrectStatus {
11 // General send
12
13 /**
14 * Sends a JSON response with a given HTTP status.
15 * @param res - The Express response object.
16 * @param status - The HTTP status code (default: 200).
17 * @param json - The JSON object to send.
18 */
19 export function send_message_on_status(res: Response, status: number = 200, json: object = { 'title': '<empty>', 'msg': 'message', 'token': '' }): void {
20 res.status(status).json(json);
21 }
22
23 // 1xx informational response
24
25 /**
26 * Sends a "100 Continue" response.
27 * @param res - The Express response object.
28 * @param json - The JSON object to send.
29 */
30 export function send_continue(res: Response, json: object): void {
31 return send_message_on_status(res, 100, json);
32 }
33
34 /**
35 * Sends a "101 Switching Protocols" response.
36 * @param res - The Express response object.
37 * @param json - The JSON object to send.
38 */
39 export function switching_protocols(res: Response, json: object): void {
40 return send_message_on_status(res, 101, json);
41 }
42
43 /**
44 * Sends a "102 Processing" response.
45 * @param res - The Express response object.
46 * @param json - The JSON object to send.
47 */
48 export function processing(res: Response, json: object): void {
49 return send_message_on_status(res, 102, json);
50 }
51
52 /**
53 * Sends a "103 Early Hints" response.
54 * @param res - The Express response object.
55 * @param json - The JSON object to send.
56 */
57 export function early_hints(res: Response, json: object): void {
58 return send_message_on_status(res, 103, json);
59 }
60
61 /**
62 * Sends a "110 Response is Stale" response.
63 * @param res - The Express response object.
64 * @param json - The JSON object to send.
65 */
66 export function response_is_stale(res: Response, json: object): void {
67 return send_message_on_status(res, 110, json);
68 }
69
70 // 2xx successful
71 /**
72 * Sends a "200 Success" response.
73 * @param res - The Express response object.
74 * @param json - The JSON object to send.
75 */
76 export function success(res: Response, json: object): void {
77 return send_message_on_status(res, 200, json);
78 }
79
80 /**
81 * Sends a "201 Created" response.
82 * @param res - The Express response object.
83 * @param json - The JSON object to send.
84 */
85 export function created(res: Response, json: object): void {
86 return send_message_on_status(res, 201, json);
87 }
88
89 /**
90 * Sends a "202 Accepted" response.
91 * @param res - The Express response object.
92 * @param json - The JSON object to send.
93 */
94 export function accepted(res: Response, json: object): void {
95 return send_message_on_status(res, 202, json);
96 }
97
98 /**
99 * Sends a "203 Non Authoritative Information" response.
100 * @param res - The Express response object.
101 * @param json - The JSON object to send.
102 */
103 export function non_authoritative_information(res: Response, json: object): void {
104 return send_message_on_status(res, 203, json);
105 }
106
107 /**
108 * Sends a "204 No Content" response.
109 * @param res - The Express response object.
110 * @param json - The JSON object to send.
111 */
112 export function no_content(res: Response, json: object): void {
113 return send_message_on_status(res, 204, json);
114 }
115
116 /**
117 * Sends a "205 Reset Content" response.
118 * @param res - The Express response object.
119 * @param json - The JSON object to send.
120 */
121 export function reset_content(res: Response, json: object): void {
122 return send_message_on_status(res, 205, json);
123 }
124
125 /**
126 * Sends a "206 Partial Content" response.
127 * @param res - The Express response object.
128 * @param json - The JSON object to send.
129 */
130 export function partial_content(res: Response, json: object): void {
131 return send_message_on_status(res, 206, json);
132 }
133
134 /**
135 * Sends a "207 Multi Status" response.
136 * @param res - The Express response object.
137 * @param json - The JSON object to send.
138 */
139 export function multi_status(res: Response, json: object): void {
140 return send_message_on_status(res, 207, json);
141 }
142
143 /**
144 * Sends a "208 Already Reported" response.
145 * @param res - The Express response object.
146 * @param json - The JSON object to send.
147 */
148 export function already_reported(res: Response, json: object): void {
149 return send_message_on_status(res, 208, json);
150 }
151
152 /**
153 * Sends a "226 Im Used" response.
154 * @param res - The Express response object.
155 * @param json - The JSON object to send.
156 */
157 export function im_used(res: Response, json: object): void {
158 return send_message_on_status(res, 226, json);
159 }
160
161 // 3xx redirection
162
163 /**
164 * Sends a "300 Multiple Choices" response.
165 * @param res - The Express response object.
166 * @param json - The JSON object to send.
167 */
168 export function multiple_choices(res: Response, json: object): void {
169 return send_message_on_status(res, 300, json);
170 }
171
172 /**
173 * Sends a "301 Moved Permanently" response.
174 * @param res - The Express response object.
175 * @param json - The JSON object to send.
176 */
177 export function moved_permanently(res: Response, json: object): void {
178 return send_message_on_status(res, 301, json);
179 }
180
181 /**
182 * Sends a "302 Found" response.
183 * @param res - The Express response object.
184 * @param json - The JSON object to send.
185 */
186 export function found(res: Response, json: object): void {
187 return send_message_on_status(res, 302, json);
188 }
189
190 /**
191 * Sends a "303 See Other" response.
192 * @param res - The Express response object.
193 * @param json - The JSON object to send.
194 */
195 export function see_other(res: Response, json: object): void {
196 return send_message_on_status(res, 303, json);
197 }
198
199 /**
200 * Sends a "304 Not Modified" response.
201 * @param res - The Express response object.
202 * @param json - The JSON object to send.
203 */
204 export function not_modified(res: Response, json: object): void {
205 return send_message_on_status(res, 304, json);
206 }
207
208 /**
209 * Sends a "305 Use Proxy" response.
210 * @param res - The Express response object.
211 * @param json - The JSON object to send.
212 */
213 export function use_proxy(res: Response, json: object): void {
214 return send_message_on_status(res, 305, json);
215 }
216
217 /**
218 * Sends a "306 Switch Proxy" response.
219 * @param res - The Express response object.
220 * @param json - The JSON object to send.
221 */
222 export function switch_proxy(res: Response, json: object): void {
223 return send_message_on_status(res, 306, json);
224 }
225
226 /**
227 * Sends a "307 Temporary Redirect" response.
228 * @param res - The Express response object.
229 * @param json - The JSON object to send.
230 */
231 export function temporary_redirect(res: Response, json: object): void {
232 return send_message_on_status(res, 307, json);
233 }
234
235 /**
236 * Sends a "308 Permanent Redirect" response.
237 * @param res - The Express response object.
238 * @param json - The JSON object to send.
239 */
240 export function permanent_redirect(res: Response, json: object): void {
241 return send_message_on_status(res, 308, json);
242 }
243
244 // 4xx client error
245
246 /**
247 * Sends a "400 Bad Request" response.
248 * @param res - The Express response object.
249 * @param json - The JSON object to send.
250 */
251 export function bad_request(res: Response, json: object): void {
252 return send_message_on_status(res, 400, json);
253 }
254
255 /**
256 * Sends a "401 Unauthorized" response.
257 * @param res - The Express response object.
258 * @param json - The JSON object to send.
259 */
260 export function unauthorized(res: Response, json: object): void {
261 return send_message_on_status(res, 401, json);
262 }
263
264 /**
265 * Sends a "402 Payment Required" response.
266 * @param res - The Express response object.
267 * @param json - The JSON object to send.
268 */
269 export function payment_required(res: Response, json: object): void {
270 return send_message_on_status(res, 402, json);
271 }
272
273 /**
274 * Sends a "403 Forbidden" response.
275 * @param res - The Express response object.
276 * @param json - The JSON object to send.
277 */
278 export function forbidden(res: Response, json: object): void {
279 return send_message_on_status(res, 403, json);
280 }
281
282 /**
283 * Sends a "404 Not Found" response.
284 * @param res - The Express response object.
285 * @param json - The JSON object to send.
286 */
287 export function not_found(res: Response, json: object): void {
288 return send_message_on_status(res, 404, json);
289 }
290
291 /**
292 * Sends a "405 Method Not Allowed" response.
293 * @param res - The Express response object.
294 * @param json - The JSON object to send.
295 */
296 export function method_not_allowed(res: Response, json: object): void {
297 return send_message_on_status(res, 405, json);
298 }
299
300 /**
301 * Sends a "406 Not Acceptable" response.
302 * @param res - The Express response object.
303 * @param json - The JSON object to send.
304 */
305 export function not_acceptable(res: Response, json: object): void {
306 return send_message_on_status(res, 406, json);
307 }
308
309 /**
310 * Sends a "407 Proxy Authentication Required" response.
311 * @param res - The Express response object.
312 * @param json - The JSON object to send.
313 */
314 export function proxy_authentication_required(res: Response, json: object): void {
315 return send_message_on_status(res, 407, json);
316 }
317
318 /**
319 * Sends a "408 Request Timeout" response.
320 * @param res - The Express response object.
321 * @param json - The JSON object to send.
322 */
323 export function request_timeout(res: Response, json: object): void {
324 return send_message_on_status(res, 408, json);
325 }
326
327 /**
328 * Sends a "409 Conflict" response.
329 * @param res - The Express response object.
330 * @param json - The JSON object to send.
331 */
332 export function conflict(res: Response, json: object): void {
333 return send_message_on_status(res, 409, json);
334 }
335
336 /**
337 * Sends a "410 Gone" response.
338 * @param res - The Express response object.
339 * @param json - The JSON object to send.
340 */
341 export function gone(res: Response, json: object): void {
342 return send_message_on_status(res, 410, json);
343 }
344
345 /**
346 * Sends a "411 Length Required" response.
347 * @param res - The Express response object.
348 * @param json - The JSON object to send.
349 */
350 export function length_required(res: Response, json: object): void {
351 return send_message_on_status(res, 411, json);
352 }
353
354 /**
355 * Sends a "412 Precondition Failed" response.
356 * @param res - The Express response object.
357 * @param json - The JSON object to send.
358 */
359 export function precondition_failed(res: Response, json: object): void {
360 return send_message_on_status(res, 412, json);
361 }
362
363 /**
364 * Sends a "413 Payload Too Large" response.
365 * @param res - The Express response object.
366 * @param json - The JSON object to send.
367 */
368 export function payload_too_large(res: Response, json: object): void {
369 return send_message_on_status(res, 413, json);
370 }
371
372 /**
373 * Sends a "414 Uri Too Long" response.
374 * @param res - The Express response object.
375 * @param json - The JSON object to send.
376 */
377 export function uri_too_long(res: Response, json: object): void {
378 return send_message_on_status(res, 414, json);
379 }
380
381 /**
382 * Sends a "415 Unsupported Media Type" response.
383 * @param res - The Express response object.
384 * @param json - The JSON object to send.
385 */
386 export function unsupported_media_type(res: Response, json: object): void {
387 return send_message_on_status(res, 415, json);
388 }
389
390 /**
391 * Sends a "416 Range Not Satisfiable" response.
392 * @param res - The Express response object.
393 * @param json - The JSON object to send.
394 */
395 export function range_not_satisfiable(res: Response, json: object): void {
396 return send_message_on_status(res, 416, json);
397 }
398
399 /**
400 * Sends a "417 Expectation Failed" response.
401 * @param res - The Express response object.
402 * @param json - The JSON object to send.
403 */
404 export function expectation_failed(res: Response, json: object): void {
405 return send_message_on_status(res, 417, json);
406 }
407
408 /**
409 * Sends a "418 Im A Teapot" response.
410 * @param res - The Express response object.
411 * @param json - The JSON object to send.
412 */
413 export function im_a_teapot(res: Response, json: object): void {
414 return send_message_on_status(res, 418, json);
415 }
416
417 /**
418 * Sends a "421 Misdirected Request" response.
419 * @param res - The Express response object.
420 * @param json - The JSON object to send.
421 */
422 export function misdirected_request(res: Response, json: object): void {
423 return send_message_on_status(res, 421, json);
424 }
425
426 /**
427 * Sends a "422 Unprocessable Entity" response.
428 * @param res - The Express response object.
429 * @param json - The JSON object to send.
430 */
431 export function unprocessable_entity(res: Response, json: object): void {
432 return send_message_on_status(res, 422, json);
433 }
434
435 /**
436 * Sends a "423 locked" response.
437 * @param res - The Express response object.
438 * @param json - The JSON object to send.
439 */
440 export function locked(res: Response, json: object): void {
441 return send_message_on_status(res, 423, json);
442 }
443
444 /**
445 * Sends a "424 Failed Dependency" response.
446 * @param res - The Express response object.
447 * @param json - The JSON object to send.
448 */
449 export function failed_dependency(res: Response, json: object): void {
450 return send_message_on_status(res, 424, json);
451 }
452
453 /**
454 * Sends a "425 Too Early" response.
455 * @param res - The Express response object.
456 * @param json - The JSON object to send.
457 */
458 export function too_early(res: Response, json: object): void {
459 return send_message_on_status(res, 425, json);
460 }
461
462 /**
463 * Sends a "426 Upgrade Required" response.
464 * @param res - The Express response object.
465 * @param json - The JSON object to send.
466 */
467 export function upgrade_required(res: Response, json: object): void {
468 return send_message_on_status(res, 426, json);
469 }
470
471 /**
472 * Sends a "428 Precondition Required" response.
473 * @param res - The Express response object.
474 * @param json - The JSON object to send.
475 */
476 export function precondition_required(res: Response, json: object): void {
477 return send_message_on_status(res, 428, json);
478 }
479
480 /**
481 * Sends a "429 Too Many Requests" response.
482 * @param res - The Express response object.
483 * @param json - The JSON object to send.
484 */
485 export function too_many_requests(res: Response, json: object): void {
486 return send_message_on_status(res, 429, json);
487 }
488
489 /**
490 * Sends a "431 Request Header Fields Too Large" response.
491 * @param res - The Express response object.
492 * @param json - The JSON object to send.
493 */
494 export function request_header_fields_too_large(res: Response, json: object): void {
495 return send_message_on_status(res, 431, json);
496 }
497
498 /**
499 * Sends a "451 Unavailable For Legal Reasons" response.
500 * @param res - The Express response object.
501 * @param json - The JSON object to send.
502 */
503 export function unavailable_for_legal_reasons(res: Response, json: object): void {
504 return send_message_on_status(res, 451, json);
505 }
506
507 /**
508 * Sends a "498 Invalid Token" response.
509 * @param res - The Express response object.
510 * @param json - The JSON object to send.
511 */
512 export function invalid_token(res: Response, json: object): void {
513 return send_message_on_status(res, 498, json);
514 }
515
516 // 5xx server error
517
518 /**
519 * Sends a "500 Internal Server Error" response.
520 * @param res - The Express response object.
521 * @param json - The JSON object to send.
522 */
523 export function internal_server_error(res: Response, json: object): void {
524 return send_message_on_status(res, 500, json);
525 }
526
527 /**
528 * Sends a "501 Not Implemented" response.
529 * @param res - The Express response object.
530 * @param json - The JSON object to send.
531 */
532 export function not_implemented(res: Response, json: object): void {
533 return send_message_on_status(res, 501, json);
534 }
535
536 /**
537 * Sends a "502 Bad Gateway" response.
538 * @param res - The Express response object.
539 * @param json - The JSON object to send.
540 */
541 export function bad_gateway(res: Response, json: object): void {
542 return send_message_on_status(res, 502, json);
543 }
544
545 /**
546 * Sends a "503 Service Unavailable" response.
547 * @param res - The Express response object.
548 * @param json - The JSON object to send.
549 */
550 export function service_unavailable(res: Response, json: object): void {
551 return send_message_on_status(res, 503, json);
552 }
553
554 /**
555 * Sends a "504 Gateway Timeout" response.
556 * @param res - The Express response object.
557 * @param json - The JSON object to send.
558 */
559 export function gateway_timeout(res: Response, json: object): void {
560 return send_message_on_status(res, 504, json);
561 }
562
563 /**
564 * Sends a "505 Http Version Not Supported" response.
565 * @param res - The Express response object.
566 * @param json - The JSON object to send.
567 */
568 export function http_version_not_supported(res: Response, json: object): void {
569 return send_message_on_status(res, 505, json);
570 }
571
572 /**
573 * Sends a "506 Variant Also Negotiates" response.
574 * @param res - The Express response object.
575 * @param json - The JSON object to send.
576 */
577 export function variant_also_negotiates(res: Response, json: object): void {
578 return send_message_on_status(res, 506, json);
579 }
580
581 /**
582 * Sends a "507 Insufficient Storage" response.
583 * @param res - The Express response object.
584 * @param json - The JSON object to send.
585 */
586 export function insufficient_storage(res: Response, json: object): void {
587 return send_message_on_status(res, 507, json);
588 }
589
590 /**
591 * Sends a "508 Loop Detected" response.
592 * @param res - The Express response object.
593 * @param json - The JSON object to send.
594 */
595 export function loop_detected(res: Response, json: object): void {
596 return send_message_on_status(res, 508, json);
597 }
598
599 /**
600 * Sends a "510 Not Extended" response.
601 * @param res - The Express response object.
602 * @param json - The JSON object to send.
603 */
604 export function not_extended(res: Response, json: object): void {
605 return send_message_on_status(res, 510, json);
606 }
607
608 /**
609 * Sends a "511 Network Authentication Required" response.
610 * @param res - The Express response object.
611 * @param json - The JSON object to send.
612 */
613 export function network_authentication_required(res: Response, json: object): void {
614 return send_message_on_status(res, 511, json);
615 }
616}