BookingService/utils/handler.py

16 lines
465 B
Python

from rest_framework.views import exception_handler
def custom_exception_handler(exc, context):
# Call REST framework's default exception handler first,
# to get the standard error response.
response = exception_handler(exc, context)
# Now add the HTTP status code to the response.
if response and response.status_code == 400:
data = response.data
response.data = {}
response.data['detail'] = data
return response