update
This commit is contained in:
parent
8b0cddf7e2
commit
9ecc590c9d
@ -8,6 +8,9 @@ class Settings(BaseSettings):
|
||||
|
||||
API_BASE_URL: str = "https://api-dev.beefast.co"
|
||||
|
||||
# 企业微信机器人系统异常通知
|
||||
URL_WECOMBOT_SYS_EXCEPTION : str = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=edcc54c5-c352-42dd-b9be-0cc5b39cc0dc"
|
||||
|
||||
# 积分别名
|
||||
POINT_ALIAS: str = "蜂蜜"
|
||||
POINT_RATIO: float = 10.0 # 积分兑换比例
|
||||
|
||||
32
app/main.py
32
app/main.py
@ -9,6 +9,8 @@ from fastapi import HTTPException
|
||||
from app.middleware.request_logger import RequestLoggerMiddleware
|
||||
from app.core.response import CustomJSONResponse
|
||||
import logging
|
||||
from app.core.config import settings
|
||||
from app.core.wecombot import WecomBot
|
||||
|
||||
# 创建数据库表
|
||||
Base.metadata.create_all(bind=engine)
|
||||
@ -70,17 +72,27 @@ async def root():
|
||||
async def health_check():
|
||||
return {"status": "healthy"}
|
||||
|
||||
@app.exception_handler(RequestValidationError)
|
||||
async def validation_exception_handler(request, exc):
|
||||
logging.exception(f"请求参数错误: {str(exc)}")
|
||||
return CustomJSONResponse(
|
||||
status_code=400,
|
||||
content=str(exc)
|
||||
)
|
||||
|
||||
@app.exception_handler(HTTPException)
|
||||
async def http_exception_handler(request, exc):
|
||||
logging.exception(f"HTTP异常: {str(exc)}")
|
||||
@app.exception_handler(Exception)
|
||||
async def exception_handler(request, exc):
|
||||
logging.exception(f"API异常: {str(exc)}")
|
||||
|
||||
# 发送企业微信消息
|
||||
wecom_bot = WecomBot(settings.URL_WECOMBOT_SYS_EXCEPTION)
|
||||
|
||||
|
||||
exception_log = f"""**API异常**
|
||||
**请求信息**
|
||||
> 请求方法:{request.method}
|
||||
> 请求URL:{request.url}
|
||||
> 请求头:{request.headers}
|
||||
> 请求体:{request.body}
|
||||
|
||||
**异常信息**
|
||||
{str(exc)}
|
||||
"""
|
||||
|
||||
await wecom_bot.send_markdown(exception_log)
|
||||
|
||||
return CustomJSONResponse(
|
||||
status_code=exc.status_code,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user