def custom_exception_handler(exc, context=None):
 if settings.DEBUG_PROPAGATE_EXCEPTIONS:
  raise
 response = exception_handler(exc, context)
 if (response is None):
  data = {'detail': 'Internal Server Error'}
  if settings.DEBUG:
   data['traceback'] = traceback.format_exc()
  request = context.get('request')
  sender = context.get('view').__class__
  got_request_exception.send(sender, request=request)
  response = Response(data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
 return response

def custom_exception_handler ( exc , context = None ) : if settings . DEBUG_PROPAGATE_EXCEPTIONS : raise response = exception_handler ( exc , context ) if ( response is None ) : data = { 'detail' : 'Internal Server Error' } if settings . DEBUG : data [ 'traceback' ] = traceback . format_exc ( ) request = context . get ( 'request' ) sender = context . get ( 'view' ) . __class__ got_request_exception . send ( sender , request = request ) response = Response ( data , status = status . HTTP_500_INTERNAL_SERVER_ERROR ) return response
custom exception handler for drf .