File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33from django .core .exceptions import ValidationError
44from django .db .models .deletion import RestrictedError
5+ from rest_framework .exceptions import ParseError
56from rest_framework .response import Response
67from 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
You can’t perform that action at this time.
0 commit comments