summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2020-09-07 13:33:47 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-09-09 09:04:28 +0200
commit2808cdc8fb15ad27f83af3e62db69f5ea7ced29e (patch)
tree8a2d09cad742e8f839bdb6ce21b6dc1bc2c73e82 /django/core
parentfc1446073ed9636047c48796cc20772ab60e12b0 (diff)
Fixed #31962 -- Made SessionMiddleware raise SessionInterrupted when session destroyed while request is processing.
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