INNER CODE UNIT · Python

rate_limit_handler

GHJJ123/brainrotguard · web/app.py:42

async def rate_limit_handler(request: Request, exc: RateLimitExceeded):
    locale = normalize_locale(getattr(request.app.state, "locale", "en"))
    headers = {"Retry-After": "5"}
    if request.url.path.startswith("/api/"):
        return JSONResponse(
            content={
                "error": "rate_limited",
                "message": t(locale, "Please wait a moment and try again."),
            },
            status_code=429,
            headers=headers,
        )
    return HTMLResponse(
        content=f"<h1>{t(locale, 'Too many requests')}</h1><p>{t(locale, 'Please wait a moment and try again.')}</p>",
        status_code=429,
        headers=headers,
    )

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…