summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
Diffstat (limited to 'django/core')
-rw-r--r--django/core/exceptions.py5
-rw-r--r--django/core/handlers/exception.py13
2 files changed, 17 insertions, 1 deletions
diff --git a/django/core/exceptions.py b/django/core/exceptions.py
index 2b3e55fe49..5780ffdb4a 100644
--- a/django/core/exceptions.py
+++ b/django/core/exceptions.py
@@ -71,6 +71,11 @@ class RequestAborted(Exception):
pass
+class BadRequest(Exception):
+ """The request is malformed and cannot be processed."""
+ pass
+
+
class PermissionDenied(Exception):
"""The user did not have permission to do that"""
pass
diff --git a/django/core/handlers/exception.py b/django/core/handlers/exception.py
index 98fb46083a..70b23edb62 100644
--- a/django/core/handlers/exception.py
+++ b/django/core/handlers/exception.py
@@ -8,7 +8,7 @@ from asgiref.sync import sync_to_async
from django.conf import settings
from django.core import signals
from django.core.exceptions import (
- PermissionDenied, RequestDataTooBig, SuspiciousOperation,
+ BadRequest, PermissionDenied, RequestDataTooBig, SuspiciousOperation,
TooManyFieldsSent,
)
from django.http import Http404
@@ -76,6 +76,17 @@ def response_for_exception(request, exc):
exc_info=sys.exc_info(),
)
+ elif isinstance(exc, BadRequest):
+ if settings.DEBUG:
+ response = debug.technical_500_response(request, *sys.exc_info(), status_code=400)
+ else:
+ response = get_exception_response(request, get_resolver(get_urlconf()), 400, exc)
+ log_response(
+ '%s: %s', str(exc), request.path,
+ response=response,
+ request=request,
+ exc_info=sys.exc_info(),
+ )
elif isinstance(exc, SuspiciousOperation):
if isinstance(exc, (RequestDataTooBig, TooManyFieldsSent)):
# POST data can't be accessed again, otherwise the original