|
|
@@ -6,6 +6,7 @@
|
|
|
from rest_framework.views import exception_handler
|
|
|
from rest_framework.views import Response
|
|
|
from rest_framework import status
|
|
|
+from rest_framework.exceptions import ValidationError, ErrorDetail
|
|
|
|
|
|
|
|
|
def custom_exception_handler(exc, context):
|
|
|
@@ -18,8 +19,16 @@ def custom_exception_handler(exc, context):
|
|
|
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR, exception=True)
|
|
|
|
|
|
else:
|
|
|
+ msg = '{exc}'.format(exc=exc)
|
|
|
+ if isinstance(exc, ValidationError):
|
|
|
+ for key, value in exc.get_full_details().items():
|
|
|
+ if value and isinstance(value, list):
|
|
|
+ value = value[0]["message"]
|
|
|
+ if isinstance(value, ErrorDetail):
|
|
|
+ msg = f"{key} {value}"
|
|
|
+
|
|
|
return Response({
|
|
|
'code': response.status_code,
|
|
|
- 'msg': '{exc}'.format(exc=exc),
|
|
|
+ 'msg': msg,
|
|
|
'data': ''
|
|
|
}, status=200, exception=True)
|