Updated the rate limit

This commit is contained in:
2026-01-29 13:37:13 +08:00
parent fe23f8424c
commit 1800ba4362
2 changed files with 13 additions and 2 deletions

View File

@@ -42,7 +42,18 @@ def create_application() -> FastAPI:
# Set up Rate Limiter
application.state.limiter = limiter
application.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
@application.exception_handler(RateLimitExceeded)
async def custom_rate_limit_exceeded_handler(request, exc):
from fastapi.responses import JSONResponse
return JSONResponse(
status_code=429,
content={
"error": "Too Many Requests",
"message": "Chill out! You've reached the rate limit. Please wait a moment before trying again.",
"limit": str(exc.detail)
}
)
# Include routes
application.include_router(api_router, prefix="/api/v1")