From e9e8fdb4df48ae81da6fef0a7c2be80ed66ab0f5 Mon Sep 17 00:00:00 2001 From: MingxuanGame Date: Tue, 12 Aug 2025 06:05:04 +0000 Subject: [PATCH] feat(api): add ppy-compatible error response --- main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 5d816f7..279a1ef 100644 --- a/main.py +++ b/main.py @@ -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. "