cleanup
This commit is contained in:
parent
da7d25d29e
commit
e7953b104b
1 changed files with 6 additions and 4 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.utils import timezone
|
||||||
from rest_framework.exceptions import APIException
|
from rest_framework.exceptions import APIException
|
||||||
from rest_framework.views import exception_handler as drf_exception_handler
|
from rest_framework.views import exception_handler as drf_exception_handler
|
||||||
|
|
||||||
|
|
@ -13,7 +15,7 @@ def exception_handler(exc, context):
|
||||||
response_data = {
|
response_data = {
|
||||||
'success': False,
|
'success': False,
|
||||||
'status_code': response.status_code,
|
'status_code': response.status_code,
|
||||||
'message': str(exc.default_detail),
|
'status_message': str(exc.default_detail),
|
||||||
'details': exc.detail,
|
'details': exc.detail,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,6 +46,7 @@ def exception_handler(exc, context):
|
||||||
# response_data['message'] = message
|
# response_data['message'] = message
|
||||||
response_data['details'] = exc.detail if isinstance(exc.detail, dict) else {}
|
response_data['details'] = exc.detail if isinstance(exc.detail, dict) else {}
|
||||||
response_data['details']['error'] = error
|
response_data['details']['error'] = error
|
||||||
|
response_data['details']['timestamp'] = timezone.now().isoformat()
|
||||||
|
|
||||||
response.data = response_data
|
response.data = response_data
|
||||||
|
|
||||||
|
|
@ -67,9 +70,8 @@ class ErrorMiddleware:
|
||||||
{
|
{
|
||||||
"success": False,
|
"success": False,
|
||||||
"status_code": 500,
|
"status_code": 500,
|
||||||
'error_code': 500,
|
"status_message": "Internal server error",
|
||||||
"message": "Internal server error",
|
"details": str(exception) if settings.DEBUG else None,
|
||||||
"details": str(exception) # فقط در حالت توسعه! در تولید بهتر است لاگ شود.
|
|
||||||
},
|
},
|
||||||
status=500
|
status=500
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue