feat 更新响应模板
fix
This commit is contained in:
15
app/main.py
15
app/main.py
@@ -1,13 +1,16 @@
|
||||
import logging.config
|
||||
from http.client import HTTPException
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi import FastAPI, HTTPException, Request
|
||||
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
|
||||
from app.api.api_route import router
|
||||
from app.core.config import settings
|
||||
from app.schemas.response_template import ResponseModel
|
||||
from logging_env import LOGGER_CONFIG_DICT
|
||||
|
||||
|
||||
logging.config.dictConfig(LOGGER_CONFIG_DICT)
|
||||
logging.getLogger("pika").setLevel(logging.WARNING)
|
||||
|
||||
@@ -36,5 +39,15 @@ def get_application() -> FastAPI:
|
||||
|
||||
|
||||
app = get_application()
|
||||
|
||||
|
||||
@app.exception_handler(HTTPException)
|
||||
async def http_exception_handler(request: Request, exc: HTTPException):
|
||||
return JSONResponse(
|
||||
status_code=exc.status_code,
|
||||
content=ResponseModel(code=exc.status_code, msg=exc.detail, data=exc.detail).dict()
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
|
||||
Reference in New Issue
Block a user