Skip to content

Commit 2b5c9b6

Browse files
authored
JSON Parsing Errors: Make errors less verbose (#10891)
* JSON Parsing Errors: Make errors less verbose * Only intercept when JSON is invalid
1 parent ba009ef commit 2b5c9b6

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

dojo/api_v2/exception_handler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from django.core.exceptions import ValidationError
44
from django.db.models.deletion import RestrictedError
5+
from rest_framework.exceptions import ParseError
56
from rest_framework.response import Response
67
from rest_framework.status import (
78
HTTP_400_BAD_REQUEST,
@@ -20,7 +21,11 @@ def custom_exception_handler(exc, context):
2021
# to get the standard error response.
2122
response = exception_handler(exc, context)
2223

23-
if isinstance(exc, RestrictedError):
24+
if isinstance(exc, ParseError) and "JSON parse error" in str(exc):
25+
response = Response()
26+
response.status_code = HTTP_400_BAD_REQUEST
27+
response.data = {"message": "JSON request content is malformed"}
28+
elif isinstance(exc, RestrictedError):
2429
# An object cannot be deleted because it has dependent objects.
2530
response = Response()
2631
response.status_code = HTTP_409_CONFLICT

0 commit comments

Comments
 (0)