-
-
Notifications
You must be signed in to change notification settings - Fork 979
Expand file tree
/
Copy patherrors.py
More file actions
2747 lines (2276 loc) · 105 KB
/
errors.py
File metadata and controls
2747 lines (2276 loc) · 105 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2013 by Rackspace Hosting, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""HTTP error classes and other Falcon-specific errors.
This module implements a collection of `falcon.HTTPError`
specializations that can be raised to generate a 4xx or 5xx HTTP
response. All classes are available directly from the `falcon`
package namespace::
import falcon
class MessageResource:
def on_get(self, req, resp):
# -- snip --
raise falcon.HTTPBadRequest(
title='TTL Out of Range',
description='The message's TTL must be between 60 and 300 seconds.'
)
# -- snip --
"""
from __future__ import annotations
from collections.abc import Iterable
from datetime import datetime
from typing import Any, TYPE_CHECKING, Union
from falcon.http_error import HTTPError
import falcon.status_codes as status
from falcon.util import deprecation
from falcon.util.misc import dt_to_http
if TYPE_CHECKING:
from falcon._typing import HeaderArg
from falcon.typing import Headers
__all__ = (
'CompatibilityError',
'DelimiterError',
'HeaderNotSupported',
'HTTPBadGateway',
'HTTPBadRequest',
'HTTPConflict',
'HTTPFailedDependency',
'HTTPForbidden',
'HTTPGatewayTimeout',
'HTTPGone',
'HTTPInsufficientStorage',
'HTTPInternalServerError',
'HTTPInvalidHeader',
'HTTPInvalidParam',
'HTTPLengthRequired',
'HTTPLocked',
'HTTPLoopDetected',
'HTTPMethodNotAllowed',
'HTTPMissingHeader',
'HTTPMissingParam',
'HTTPNetworkAuthenticationRequired',
'HTTPNotAcceptable',
'HTTPNotFound',
'HTTPNotImplemented',
'HTTPContentTooLarge',
'HTTPPreconditionFailed',
'HTTPPreconditionRequired',
'HTTPRangeNotSatisfiable',
'HTTPRequestHeaderFieldsTooLarge',
'HTTPRouteNotFound',
'HTTPServiceUnavailable',
'HTTPTooManyRequests',
'HTTPUnauthorized',
'HTTPUnavailableForLegalReasons',
'HTTPUnprocessableEntity',
'HTTPUnsupportedMediaType',
'HTTPUriTooLong',
'HTTPVersionNotSupported',
'InvalidMediaRange',
'InvalidMediaType',
'MediaMalformedError',
'MediaNotFoundError',
'MediaValidationError',
'MultipartParseError',
'OperationNotAllowed',
'PayloadTypeError',
'UnsupportedError',
'UnsupportedScopeError',
'WebSocketDisconnected',
'WebSocketHandlerNotFound',
'WebSocketPathNotFound',
'WebSocketServerError',
)
class HeaderNotSupported(ValueError):
"""The specified header is not supported by this method."""
class CompatibilityError(ValueError):
"""The given method, value, or type is not compatible."""
class InvalidMediaType(ValueError):
"""The provided media type cannot be parsed into type/subtype."""
class InvalidMediaRange(InvalidMediaType):
"""The media range contains an invalid media type and/or the q value."""
class UnsupportedScopeError(RuntimeError):
"""The ASGI scope type is not supported by Falcon."""
class UnsupportedError(RuntimeError):
"""The method or operation is not supported."""
# NOTE(kgriffs): This inherits from ValueError to be consistent with the type
# raised by Python's built-in file-like objects.
class OperationNotAllowed(ValueError):
"""The requested operation is not allowed."""
class DelimiterError(OSError):
"""The read operation did not find the requested stream delimiter."""
class PayloadTypeError(TypeError):
"""The WebSocket message payload was not of the expected type."""
class WebSocketDisconnected(ConnectionError):
"""The websocket connection is lost.
This error is raised when attempting to perform an operation on the
WebSocket and it is determined that either the client has closed the
connection, the server closed the connection, or the socket has otherwise
been lost.
Keyword Args:
code (int): The WebSocket close code, as per the WebSocket spec
(default ``1000``).
"""
code: int
"""The WebSocket close code, as per the WebSocket spec."""
def __init__(self, code: int | None = None) -> None:
self.code = code or 1000 # Default to "Normal Closure"
class WebSocketPathNotFound(WebSocketDisconnected):
"""No route could be found for the requested path.
A simulated WebSocket connection was attempted but the path specified in
the handshake request did not match any of the app's routes.
"""
pass
class WebSocketHandlerNotFound(WebSocketDisconnected):
"""The routed resource does not contain an ``on_websocket()`` handler."""
pass
class WebSocketServerError(WebSocketDisconnected):
"""The server encountered an unexpected error."""
pass
HTTPErrorKeywordArguments = Union[str, int, None]
# TODO(vytas): Passing **kwargs down to HTTPError results in arg-type error in
# Mypy, because it is impossible to verify that, e.g., an int value was not
# erroneously passed to href instead of code, etc.
#
# It is hard to properly type this on older Pythons, so we just sprinkle type
# ignores on the super().__init__(...) calls below. In any case, this call is
# internal to the framework.
#
# On Python 3.11+, I have verified it is possible to properly type this
# pattern using typing.Unpack:
#
# class HTTPErrorKeywordArguments(TypedDict):
# href: Optional[str]
# href_text: Optional[str]
# code: Optional[int]
#
# class HTTPErrorSubclass(HTTPError):
# def __init__(
# self,
# *,
# title: Optional[str] = None,
# description: Optional[str] = None,
# headers: Optional[HeaderList] = None,
# **kwargs: Unpack[HTTPErrorKeywordArguments],
# ) -> None:
# super().__init__(
# status.HTTP_400,
# title=title,
# description=description,
# headers=headers,
# **kwargs,
# )
RetryAfter = Union[int, datetime, None]
class HTTPBadRequest(HTTPError):
"""400 Bad Request.
The server cannot or will not process the request due to something
that is perceived to be a client error (e.g., malformed request
syntax, invalid request message framing, or deceptive request
routing).
(See also: RFC 9110, Section 15.5.1)
All the arguments are defined as keyword-only.
Keyword Args:
title (str): Error title (default '400 Bad Request').
description (str): Human-friendly description of the error, along with
a helpful suggestion or two.
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
def __init__(
self,
*,
title: str | None = None,
description: str | None = None,
headers: HeaderArg | None = None,
**kwargs: HTTPErrorKeywordArguments,
) -> None:
super().__init__(
status.HTTP_400,
title=title,
description=description,
headers=headers,
**kwargs, # type: ignore[arg-type]
)
class HTTPUnauthorized(HTTPError):
"""401 Unauthorized.
The request has not been applied because it lacks valid
authentication credentials for the target resource.
The server generating a 401 response MUST send a WWW-Authenticate
header field containing at least one challenge applicable to the
target resource.
If the request included authentication credentials, then the 401
response indicates that authorization has been refused for those
credentials. The user agent MAY repeat the request with a new or
replaced Authorization header field. If the 401 response contains
the same challenge as the prior response, and the user agent has
already attempted authentication at least once, then the user agent
SHOULD present the enclosed representation to the user, since it
usually contains relevant diagnostic information.
(See also: RFC 9110, Section 15.5.2)
All the arguments are defined as keyword-only.
Keyword Args:
title (str): Error title (default '401 Unauthorized').
description (str): Human-friendly description of the error, along with
a helpful suggestion or two.
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
challenges (iterable of str): One or more authentication
challenges to use as the value of the WWW-Authenticate header in
the response.
Note:
The existing value of the WWW-Authenticate in headers will be
overridden by this value
(See also: RFC 9110, Section 11.6.1)
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
def __init__(
self,
*,
title: str | None = None,
description: str | None = None,
headers: HeaderArg | None = None,
challenges: Iterable[str] | None = None,
**kwargs: HTTPErrorKeywordArguments,
):
if challenges:
headers = _load_headers(headers)
headers['WWW-Authenticate'] = ', '.join(challenges)
super().__init__(
status.HTTP_401,
title=title,
description=description,
headers=headers,
**kwargs, # type: ignore[arg-type]
)
class HTTPForbidden(HTTPError):
"""403 Forbidden.
The server understood the request but refuses to authorize it.
A server that wishes to make public why the request has been
forbidden can describe that reason in the response payload (if any).
If authentication credentials were provided in the request, the
server considers them insufficient to grant access. The client
SHOULD NOT automatically repeat the request with the same
credentials. The client MAY repeat the request with new or different
credentials. However, a request might be forbidden for reasons
unrelated to the credentials.
An origin server that wishes to "hide" the current existence of a
forbidden target resource MAY instead respond with a status code of
404 Not Found.
(See also: RFC 9110, Section 15.5.4)
All the arguments are defined as keyword-only.
Keyword Args:
title (str): Error title (default '403 Forbidden').
description (str): Human-friendly description of the error, along with
a helpful suggestion or two.
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
def __init__(
self,
*,
title: str | None = None,
description: str | None = None,
headers: HeaderArg | None = None,
**kwargs: HTTPErrorKeywordArguments,
):
super().__init__(
status.HTTP_403,
title=title,
description=description,
headers=headers,
**kwargs, # type: ignore[arg-type]
)
class HTTPNotFound(HTTPError):
"""404 Not Found.
The origin server did not find a current representation for the
target resource or is not willing to disclose that one exists.
A 404 status code does not indicate whether this lack of
representation is temporary or permanent; the 410 Gone status code
is preferred over 404 if the origin server knows, presumably through
some configurable means, that the condition is likely to be
permanent.
A 404 response is cacheable by default; i.e., unless otherwise
indicated by the method definition or explicit cache controls.
(See also: RFC 9110, Section 15.5.5)
All the arguments are defined as keyword-only.
Keyword Args:
title (str): Human-friendly error title. If not provided, and
`description` is also not provided, no body will be included
in the response.
description (str): Human-friendly description of the error, along with
a helpful suggestion or two (default ``None``).
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
def __init__(
self,
*,
title: str | None = None,
description: str | None = None,
headers: HeaderArg | None = None,
**kwargs: HTTPErrorKeywordArguments,
):
super().__init__(
status.HTTP_404,
title=title,
description=description,
headers=headers,
**kwargs, # type: ignore[arg-type]
)
class HTTPRouteNotFound(HTTPNotFound):
"""404 Not Found.
The request did not match any routes configured for the application.
This subclass of :class:`~.HTTPNotFound` is raised by the framework to
provide a default 404 response when no route matches the request. This
behavior can be customized by registering a custom error handler for
:class:`~.HTTPRouteNotFound`.
All the arguments are defined as keyword-only.
Keyword Args:
title (str): Human-friendly error title. If not provided, and
`description` is also not provided, no body will be included
in the response.
description (str): Human-friendly description of the error, along with
a helpful suggestion or two (default ``None``).
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
class HTTPMethodNotAllowed(HTTPError):
"""405 Method Not Allowed.
The method received in the request-line is known by the origin
server but not supported by the target resource.
The origin server MUST generate an Allow header field in a 405
response containing a list of the target resource's currently
supported methods.
A 405 response is cacheable by default; i.e., unless otherwise
indicated by the method definition or explicit cache controls.
(See also: RFC 9110, Section 15.5.6)
`allowed_methods` is the only positional argument allowed,
the other arguments are defined as keyword-only.
Args:
allowed_methods (list of str): Allowed HTTP methods for this
resource (e.g., ``['GET', 'POST', 'HEAD']``).
Note:
If previously set, the Allow response header will be
overridden by this value.
Keyword Args:
title (str): Human-friendly error title. If not provided, and
`description` is also not provided, no body will be included
in the response.
description (str): Human-friendly description of the error, along with
a helpful suggestion or two (default ``None``).
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
def __init__(
self,
allowed_methods: Iterable[str],
*,
title: str | None = None,
description: str | None = None,
headers: HeaderArg | None = None,
**kwargs: HTTPErrorKeywordArguments,
):
headers = _load_headers(headers)
headers['Allow'] = ', '.join(allowed_methods)
super().__init__(
status.HTTP_405,
title=title,
description=description,
headers=headers,
**kwargs, # type: ignore[arg-type]
)
class HTTPNotAcceptable(HTTPError):
"""406 Not Acceptable.
The target resource does not have a current representation that
would be acceptable to the user agent, according to the proactive
negotiation header fields received in the request, and the server
is unwilling to supply a default representation.
The server SHOULD generate a payload containing a list of available
representation characteristics and corresponding resource
identifiers from which the user or user agent can choose the one
most appropriate. A user agent MAY automatically select the most
appropriate choice from that list. However, this specification does
not define any standard for such automatic selection, as described
in RFC 9110, Section 15.4.1
(See also: RFC 9110, Section 15.5.7)
All the arguments are defined as keyword-only.
Keyword Args:
description (str): Human-friendly description of the error, along with
a helpful suggestion or two.
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
def __init__(
self,
*,
title: str | None = None,
description: str | None = None,
headers: HeaderArg | None = None,
**kwargs: HTTPErrorKeywordArguments,
):
super().__init__(
status.HTTP_406,
title=title,
description=description,
headers=headers,
**kwargs, # type: ignore[arg-type]
)
class HTTPConflict(HTTPError):
"""409 Conflict.
The request could not be completed due to a conflict with the
current state of the target resource. This code is used in
situations where the user might be able to resolve the conflict and
resubmit the request.
The server SHOULD generate a payload that includes enough
information for a user to recognize the source of the conflict.
Conflicts are most likely to occur in response to a PUT request. For
example, if versioning were being used and the representation being
PUT included changes to a resource that conflict with those made by
an earlier (third-party) request, the origin server might use a 409
response to indicate that it can't complete the request. In this
case, the response representation would likely contain information
useful for merging the differences based on the revision history.
(See also: RFC 9110, Section 15.5.10)
All the arguments are defined as keyword-only.
Keyword Args:
title (str): Error title (default '409 Conflict').
description (str): Human-friendly description of the error, along with
a helpful suggestion or two.
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
def __init__(
self,
*,
title: str | None = None,
description: str | None = None,
headers: HeaderArg | None = None,
**kwargs: HTTPErrorKeywordArguments,
):
super().__init__(
status.HTTP_409,
title=title,
description=description,
headers=headers,
**kwargs, # type: ignore[arg-type]
)
class HTTPGone(HTTPError):
"""410 Gone.
The target resource is no longer available at the origin server and
this condition is likely to be permanent.
If the origin server does not know, or has no facility to determine,
whether or not the condition is permanent, the status code 404 Not
Found ought to be used instead.
The 410 response is primarily intended to assist the task of web
maintenance by notifying the recipient that the resource is
intentionally unavailable and that the server owners desire that
remote links to that resource be removed. Such an event is common
for limited-time, promotional services and for resources belonging
to individuals no longer associated with the origin server's site.
It is not necessary to mark all permanently unavailable resources as
"gone" or to keep the mark for any length of time -- that is left to
the discretion of the server owner.
A 410 response is cacheable by default; i.e., unless otherwise
indicated by the method definition or explicit cache controls.
(See also: RFC 9110, Section 15.5.11)
All the arguments are defined as keyword-only.
Keyword Args:
title (str): Human-friendly error title. If not provided, and
`description` is also not provided, no body will be included
in the response.
description (str): Human-friendly description of the error, along with
a helpful suggestion or two (default ``None``).
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
def __init__(
self,
*,
title: str | None = None,
description: str | None = None,
headers: HeaderArg | None = None,
**kwargs: HTTPErrorKeywordArguments,
):
super().__init__(
status.HTTP_410,
title=title,
description=description,
headers=headers,
**kwargs, # type: ignore[arg-type]
)
class HTTPLengthRequired(HTTPError):
"""411 Length Required.
The server refuses to accept the request without a defined Content-
Length.
The client MAY repeat the request if it adds a valid Content-Length
header field containing the length of the message body in the
request message.
(See also: RFC 9110, Section 15.5.12)
All the arguments are defined as keyword-only.
Keyword Args:
title (str): Error title (default '411 Length Required').
description (str): Human-friendly description of the error, along with
a helpful suggestion or two.
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
def __init__(
self,
*,
title: str | None = None,
description: str | None = None,
headers: HeaderArg | None = None,
**kwargs: HTTPErrorKeywordArguments,
):
super().__init__(
status.HTTP_411,
title=title,
description=description,
headers=headers,
**kwargs, # type: ignore[arg-type]
)
class HTTPPreconditionFailed(HTTPError):
"""412 Precondition Failed.
One or more conditions given in the request header fields evaluated
to false when tested on the server.
This response code allows the client to place preconditions on the
current resource state (its current representations and metadata)
and, thus, prevent the request method from being applied if the
target resource is in an unexpected state.
(See also: RFC 9110, Section 15.5.13)
All the arguments are defined as keyword-only.
Keyword Args:
title (str): Error title (default '412 Precondition Failed').
description (str): Human-friendly description of the error, along with
a helpful suggestion or two.
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client
Note:
Falcon can process a list of ``tuple`` slightly faster
than a ``dict``.
href (str): A URL someone can visit to find out more information
(default ``None``). Unicode characters are percent-encoded.
href_text (str): If href is given, use this as the friendly
title/description for the link (default 'API documentation
for this error').
code (int): An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error (default ``None``).
"""
def __init__(
self,
*,
title: str | None = None,
description: str | None = None,
headers: HeaderArg | None = None,
**kwargs: HTTPErrorKeywordArguments,
):
super().__init__(
status.HTTP_412,
title=title,
description=description,
headers=headers,
**kwargs, # type: ignore[arg-type]
)
class HTTPContentTooLarge(HTTPError):
"""413 Content Too Large.
The server is refusing to process a request because the request
payload is larger than the server is willing or able to process.
The server MAY close the connection to prevent the client from
continuing the request.
If the condition is temporary, the server SHOULD generate a Retry-
After header field to indicate that it is temporary and after what
time the client MAY try again.
(See also: RFC 9110, Section 15.5.14)
All the arguments are defined as keyword-only.
Keyword Args:
title (str): Error title (default '413 Payload Too Large').
description (str): Human-friendly description of the error, along with
a helpful suggestion or two.
headers (dict or list): A ``dict`` of header names and values
to set, or a ``list`` of (*name*, *value*) tuples. Both *name* and
*value* must be of type ``str`` or ``StringType``, and only
character values 0x00 through 0xFF may be used on platforms that
use wide characters.
Note:
The Content-Type header, if present, will be overridden. If
you wish to return custom error messages, you can create
your own HTTP error class, and install an error handler
to convert it into an appropriate HTTP response for the
client