feat(card): 增加请求重试,异常错误提醒

This commit is contained in:
xingc
2025-04-17 18:15:49 +08:00
parent 862ae8fcca
commit f216d694d0
3 changed files with 33 additions and 9 deletions

View File

@@ -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)