v0.7.2测试
This commit is contained in:
@@ -11,7 +11,9 @@
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import JSONResponse
|
||||
from contextlib import asynccontextmanager
|
||||
import traceback
|
||||
import uvicorn
|
||||
|
||||
from config import settings
|
||||
@@ -78,6 +80,21 @@ app.add_middleware(
|
||||
)
|
||||
|
||||
|
||||
# 全局异常处理器
|
||||
@app.exception_handler(Exception)
|
||||
async def global_exception_handler(request: Request, exc: Exception):
|
||||
"""全局异常处理器 - 捕获所有未处理异常"""
|
||||
logger.error(f"未处理异常: {exc}", exc_info=True)
|
||||
return JSONResponse(
|
||||
status_code=500,
|
||||
content={
|
||||
"success": False,
|
||||
"message": f"服务器内部错误: {str(exc)}",
|
||||
"detail": traceback.format_exc() if settings.DEBUG else None
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# 注册路由
|
||||
app.include_router(auth.router, prefix="/api/auth", tags=["认证"])
|
||||
app.include_router(student.router, prefix="/api/student", tags=["学生端"])
|
||||
|
||||
Reference in New Issue
Block a user