v0.150.0
 1"""
 2HTTP exceptions that map to HTTP status codes.
 3
 4Raise these (or your own subclasses) from views, middleware, or helpers to
 5abort with a specific status. The framework reads `status_code` off the
 6exception and renders the matching error response.
 7"""
 8
 9
10class HTTPException(Exception):
11    """Base class for exceptions that map to HTTP status codes.
12
13    Subclass to define your own:
14
15        class PaymentRequiredError402(HTTPException):
16            status_code = 402
17    """
18
19    status_code: int = 500
20
21
22class BadRequestError400(HTTPException):
23    """The request is malformed and cannot be processed (HTTP 400)"""
24
25    status_code = 400
26
27
28class ForbiddenError403(HTTPException):
29    """The user did not have permission to do that (HTTP 403)"""
30
31    status_code = 403
32
33
34class NotFoundError404(HTTPException):
35    """The requested resource was not found (HTTP 404)"""
36
37    status_code = 404
38
39
40class UnsupportedMediaTypeError415(HTTPException):
41    """The request body is in a media type the server does not parse (HTTP 415)"""
42
43    status_code = 415
44
45
46class SuspiciousOperationError400(BadRequestError400):
47    """The user did something suspicious (HTTP 400)"""
48
49
50class SuspiciousMultipartFormError400(SuspiciousOperationError400):
51    """Suspect MIME request in multipart form data"""
52
53
54class SuspiciousFileOperationError400(SuspiciousOperationError400):
55    """A Suspicious filesystem operation was attempted"""
56
57
58class TooManyFieldsSentError400(SuspiciousOperationError400):
59    """
60    The number of fields in a GET or POST request exceeded
61    settings.DATA_UPLOAD_MAX_NUMBER_FIELDS.
62    """
63
64
65class TooManyFilesSentError400(SuspiciousOperationError400):
66    """
67    The number of fields in a GET or POST request exceeded
68    settings.DATA_UPLOAD_MAX_NUMBER_FILES.
69    """
70
71
72class RequestDataTooBigError400(SuspiciousOperationError400):
73    """
74    The size of the request (excluding any file uploads) exceeded
75    settings.DATA_UPLOAD_MAX_MEMORY_SIZE.
76    """