feat: 中间件中打印错误栈信息

This commit is contained in:
martsforever
2025-08-24 02:18:10 +08:00
parent 4126eec496
commit 4fc252be38
+2
View File
@@ -1,4 +1,5 @@
import time import time
import traceback
from fastapi import FastAPI, HTTPException from fastapi import FastAPI, HTTPException
from passlib.exc import InvalidTokenError from passlib.exc import InvalidTokenError
@@ -70,6 +71,7 @@ def add_app_middlewares(app: FastAPI):
return JSONResponse(content={"message": e.detail}, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) return JSONResponse(content={"message": e.detail}, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
except Exception as e: except Exception as e:
print(e) print(e)
traceback.print_exc()
return JSONResponse(content={"message": str(e)}, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) return JSONResponse(content={"message": str(e)}, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
return response return response