rancher check unique - pos free products check unique - 500 error handling
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from django.http import JsonResponse
|
||||
from rest_framework.views import exception_handler
|
||||
from django.conf import settings
|
||||
import traceback
|
||||
|
||||
|
||||
def custom_exception_handler(exc, context):
|
||||
@@ -11,6 +13,13 @@ def custom_exception_handler(exc, context):
|
||||
response.data['message'] = response.data.get('detail', str(exc))
|
||||
del response.data['detail']
|
||||
else:
|
||||
response = JsonResponse({'message': str(exc), 'status_code': 500})
|
||||
if settings.DEBUG:
|
||||
raise
|
||||
response = JsonResponse({
|
||||
"message": str(exc),
|
||||
"status_code": 500,
|
||||
"error_type": exc.__class__.__name__,
|
||||
"traceback": traceback.format_exc().splitlines(),
|
||||
}, status=500)
|
||||
response.status_code = 500
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user