return 400 error response if django validation error raised inside API
diff --git a/xos/xos/apibase.py b/xos/xos/apibase.py
index 69da468..81f58e8 100644
--- a/xos/xos/apibase.py
+++ b/xos/xos/apibase.py
@@ -5,6 +5,7 @@
from rest_framework.exceptions import APIException
from rest_framework.exceptions import PermissionDenied as RestFrameworkPermissionDenied
from django.core.exceptions import PermissionDenied as DjangoPermissionDenied
+from django.core.exceptions import ValidationError as DjangoValidationError
class XOSProgrammingError(APIException):
status_code=400
@@ -88,6 +89,10 @@
response=Response({'detail': {"error": "PermissionDenied", "specific_error": str(exc), "fields": {}}}, status=status.HTTP_403_FORBIDDEN)
response.exception=True
return response
+ elif isinstance(exc, DjangoValidationError):
+ response=Response({'detail': {"error": "ValidationError", "specific_error": str(exc), "fields": {}}}, status=status.HTTP_400_BAD_REQUEST)
+ response.exception=True
+ return response
else:
return super(XOSRetrieveUpdateDestroyAPIView, self).handle_exception(exc)
@@ -129,6 +134,10 @@
response=Response({'detail': {"error": "PermissionDenied", "specific_error": str(exc), "fields": {}}}, status=status.HTTP_403_FORBIDDEN)
response.exception=True
return response
+ elif isinstance(exc, DjangoValidationError):
+ response=Response({'detail': {"error": "ValidationError", "specific_error": str(exc), "fields": {}}}, status=status.HTTP_400_BAD_REQUEST)
+ response.exception=True
+ return response
else:
return super(XOSListCreateAPIView, self).handle_exception(exc)