feat(card): 增加请求重试,异常错误提醒
This commit is contained in:
16
core/app.py
16
core/app.py
@@ -6,13 +6,13 @@
|
||||
# @Desc :
|
||||
import logging
|
||||
|
||||
import redis.asyncio as aioredis
|
||||
from fastapi import FastAPI, Request, Response, status
|
||||
from fastapi import FastAPI, Request, status
|
||||
from fastapi.responses import UJSONResponse
|
||||
from fastapi.exceptions import HTTPException, RequestValidationError
|
||||
from fastapi_limiter import FastAPILimiter
|
||||
|
||||
from config import settings
|
||||
from core.base.exceptions import CardBookException
|
||||
from core.db.engine import get_cache
|
||||
from core.routers.route import routers
|
||||
from core.routers.chat.handlers import socket_manager
|
||||
@@ -76,6 +76,18 @@ def create_app() -> FastAPI:
|
||||
}
|
||||
)
|
||||
|
||||
@app.exception_handler(CardBookException)
|
||||
async def http_exception_handler(request: Request, exc: Exception):
|
||||
await exception_log(request, exc)
|
||||
return UJSONResponse(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
content={
|
||||
'status': status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
'data': None,
|
||||
'message': str(exc)
|
||||
}
|
||||
)
|
||||
|
||||
@app.exception_handler(Exception)
|
||||
async def http_exception_handler(request: Request, exc: Exception):
|
||||
await exception_log(request, exc)
|
||||
|
||||
Reference in New Issue
Block a user