This commit is contained in:
aaron 2025-02-15 14:55:52 +08:00
parent 804584550e
commit c7fcfc7443

View File

@ -8,6 +8,7 @@ from app.core.response import error_response
from fastapi import HTTPException from fastapi import HTTPException
from app.middleware.request_logger import RequestLoggerMiddleware from app.middleware.request_logger import RequestLoggerMiddleware
from app.core.response import CustomJSONResponse from app.core.response import CustomJSONResponse
import logging
# 创建数据库表 # 创建数据库表
Base.metadata.create_all(bind=engine) Base.metadata.create_all(bind=engine)
@ -66,6 +67,7 @@ async def health_check():
@app.exception_handler(RequestValidationError) @app.exception_handler(RequestValidationError)
async def validation_exception_handler(request, exc): async def validation_exception_handler(request, exc):
logging.exception(f"请求参数错误: {str(exc)}")
return CustomJSONResponse( return CustomJSONResponse(
status_code=400, status_code=400,
content=error_response( content=error_response(
@ -76,6 +78,7 @@ async def validation_exception_handler(request, exc):
@app.exception_handler(HTTPException) @app.exception_handler(HTTPException)
async def http_exception_handler(request, exc): async def http_exception_handler(request, exc):
logging.exception(f"HTTP异常: {str(exc)}")
return CustomJSONResponse( return CustomJSONResponse(
status_code=exc.status_code, status_code=exc.status_code,
content=error_response( content=error_response(