utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:ac-mediator 作者: AudioCommons 项目源码 文件源码
def custom_exception_handler(exc, context):
    """
    Custom django rest framework exception handler that includes 'status_code' field in the
    responses.
    """
    # Call REST framework's default exception handler first
    response = exception_handler(exc, context)

    # Catch unexpected exceptions
    if response is None:
        if isinstance(exc, Exception):
            data = {'detail': 'A server error occurred.'}
            set_rollback()
            response = Response(data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    # Now add the HTTP status code to the response.
    if response is not None:
        response.data['status_code'] = response.status_code
    return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号