Example #1
0
 async def all_exception_handler(request: Request, exc: Exception):
     """
     全局所有异常
     :param request:
     :param exc:
     :return:
     """
     logger.error(f"全局异常\nURL:{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")
     return response_code.resp_500(message="服务器内部错误")
Example #2
0
 async def request_validation_exception_handler(request: Request, exc: RequestValidationError):
     """
     请求参数验证异常
     :param request:
     :param exc:
     :return:
     """
     logger.error(f"请求参数格式错误\nURL:{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")
     return response_code.resp_422(message=exc.errors())
Example #3
0
    async def user_token_exception_handler(request: Request, exc: UserTokenError):
        """
        用户token异常
        :param request:
        :param exc:
        :return:
        """
        logger.error(f"用户认证异常\nURL:{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")

        return response_code.resp_5000(message=exc.err_desc)
Example #4
0
    async def query_params_exception_handler(request: Request, exc: PostParamsError):
        """
        内部查询操作时,其他参数异常
        :param request:
        :param exc:
        :return:
        """
        logger.error(f"参数查询异常\nURL:{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")

        return response_code.resp_400(message=exc.err_desc)
Example #5
0
    async def user_not_found_exception_handler(request: Request, exc: UserNotFound):
        """
        用户认证未找到
        :param request:
        :param exc:
        :return:
        """
        logger.error(f"token未知用户\nURL:{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")

        return response_code.resp_5001(message=exc.err_desc)