Beispiel #1
0
 async def all_exception_handler(request: Request, exc: Exception):
     """
     全局所有异常
     :param request:
     :param exc:
     :return:
     """
     logger.error(f"全局异常\n{request.method}URL:{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")
     return response_code.resp_500(message="服务器内部错误")
Beispiel #2
0
 async def request_validation_exception_handler(request: Request, exc: RequestValidationError):
     """
     请求参数验证异常
     :param request:
     :param exc:
     :return:
     """
     logger.error(
         f"请求参数格式错误\nURL:{request.method}{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")
     return response_code.resp_422(message=exc.errors())
Beispiel #3
0
    async def query_params_exception_handler(request: Request, exc: PostParamsError):
        """
        内部查询操作时,其他参数异常
        :param request:
        :param exc:
        :return:
        """
        logger.error(f"参数查询异常\nURL:{request.method}{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")

        return response_code.resp_400(message=exc.err_desc)
Beispiel #4
0
    async def user_token_exception_handler(request: Request, exc: UserTokenError):
        """
        用户token异常
        :param request:
        :param exc:
        :return:
        """
        logger.error(f"用户认证异常\nURL:{request.method}{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")

        return response_code.resp_5000(message=exc.err_desc)
Beispiel #5
0
def mhd_validator(filename):
    if not os.path.exists(filename):
        return False
    try:
        img = sitk.ReadImage(filename)
        nda = sitk.GetArrayFromImage(img)
    except RuntimeError:
        logger.error('Not image file')
        return False

    return True
Beispiel #6
0
    async def user_not_found_exception_handler(request: Request, exc: UserNotFound):
        """
        用户认证未找到
        :param request:
        :param exc:
        :return:
        """
        logger.error(
            f"token未知用户\nURL:{request.method}{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")

        return response_code.resp_5001(message=exc.err_desc)