exception_handler.py 文件源码

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

项目:Anonymous_message 作者: DevRoss 项目源码 文件源码
def my_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.
    # print(exc)
    # print(context)
    if response is not None:
        if isinstance(exc, exceptions.AuthenticationFailed):
            response.data['error_code'] = 2
        elif isinstance(exc, exceptions.PermissionDenied):
            response.data['error_code'] = 3
        else:
            response.data['error_code'] = 1
    return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号