修改捕获异常后日志记录信息
Signed-off-by: 刘建 <liujian_8670@qq.com>
This commit is contained in:
parent
572f494a88
commit
43ee394c21
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user