feat(api): add ppy-compatible error response

This commit is contained in:
MingxuanGame
2025-08-12 06:05:04 +00:00
parent 6474a3d11e
commit e9e8fdb4df

10
main.py
View File

@@ -19,8 +19,9 @@ from app.router import (
from app.service.daily_challenge import daily_challenge_job
from app.service.osu_rx_statistics import create_rx_statistics
from fastapi import FastAPI
from fastapi import FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
@asynccontextmanager
@@ -67,6 +68,13 @@ async def health_check():
return {"status": "ok", "timestamp": datetime.utcnow().isoformat()}
@app.exception_handler(HTTPException)
async def http_exception_handler(request: Request, exc: HTTPException):
if request.url.path.startswith("/api/v2"):
return JSONResponse(status_code=exc.status_code, content={"error": exc.detail})
raise exc
if settings.secret_key == "your_jwt_secret_here":
logger.warning(
"jwt_secret_key is unset. Your server is unsafe. "