|
@@ -1,6 +1,6 @@
|
|
|
import logging
|
|
|
-
|
|
|
-from fastapi import FastAPI
|
|
|
+from fastapi import FastAPI, HTTPException
|
|
|
+from fastapi.responses import JSONResponse
|
|
|
from app.providers import (
|
|
|
logging_provider,
|
|
|
app_provider,
|
|
@@ -37,6 +37,15 @@ def boot(_app, provider):
|
|
|
logging.info(provider.__name__ + " booted")
|
|
|
|
|
|
|
|
|
+# 添加全局异常处理器
|
|
|
+@app.exception_handler(HTTPException)
|
|
|
+async def http_exception_handler(request, exc: HTTPException):
|
|
|
+ return JSONResponse(
|
|
|
+ status_code=exc.status_code,
|
|
|
+ content={"detail": exc.detail, "message": "Resource not found."},
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
app = create_app()
|
|
|
|
|
|
|