From 43ee394c2155bffeb038ef624d135fff42c1b263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=BB=BA?= Date: Fri, 27 Oct 2023 07:43:25 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8D=95=E8=8E=B7=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=90=8E=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘建 --- kinit-api/core/exception.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/kinit-api/core/exception.py b/kinit-api/core/exception.py index 98b4316..488964a 100644 --- a/kinit-api/core/exception.py +++ b/kinit-api/core/exception.py @@ -42,8 +42,10 @@ def register_exception(app: FastAPI): """ print("请求地址", request.url.__str__()) print("捕捉到重写CustomException异常异常:custom_exception_handler") - logger.error(exc.desc) - logger.error(exc.msg) + # logger.error(exc.desc) + # logger.error(exc.msg) + # 打印栈信息,方便追踪排查异常 + logger.exception(exc) print(exc.desc) print(exc.msg) return JSONResponse( @@ -58,7 +60,9 @@ def register_exception(app: FastAPI): """ print("请求地址", request.url.__str__()) print("捕捉到重写HTTPException异常异常:unicorn_exception_handler") - logger.error(exc.detail) + # logger.error(exc.detail) + # 打印栈信息,方便追踪排查异常 + logger.exception(exc) print(exc.detail) return JSONResponse( status_code=200, @@ -75,7 +79,9 @@ def register_exception(app: FastAPI): """ print("请求地址", request.url.__str__()) print("捕捉到重写请求验证异常异常:validation_exception_handler") - logger.error(exc.errors()) + # logger.error(exc.errors()) + # 打印栈信息,方便追踪排查异常 + logger.exception(exc) print(exc.errors()) msg = exc.errors()[0].get("msg") if msg == "field required": @@ -107,7 +113,9 @@ def register_exception(app: FastAPI): """ print("请求地址", request.url.__str__()) print("捕捉到值异常:value_exception_handler") - logger.error(exc.__str__()) + # logger.error(exc.__str__()) + # 打印栈信息,方便追踪排查异常 + logger.exception(exc) print(exc.__str__()) return JSONResponse( status_code=200, @@ -126,7 +134,9 @@ def register_exception(app: FastAPI): """ print("请求地址", request.url.__str__()) print("捕捉到全局异常:all_exception_handler") - logger.error(exc.__str__()) + # logger.error(exc.__str__()) + # 打印栈信息,方便追踪排查异常 + logger.exception(exc) return JSONResponse( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=jsonable_encoder(