Updated the rate limit
This commit is contained in:
13
app/main.py
13
app/main.py
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user