INNER CODE UNIT · Python

_rate_limit_exceeded_handler

laurentS/slowapi · slowapi/extension.py:76

def _rate_limit_exceeded_handler(request: Request, exc: RateLimitExceeded) -> Response:
    """
    Build a simple JSON response that includes the details of the rate limit
    that was hit. If no limit is hit, the countdown is added to headers.
    """
    response = JSONResponse(
        {"error": f"Rate limit exceeded: {exc.detail}"}, status_code=429
    )
    response = request.app.state.limiter._inject_headers(
        response, request.state.view_rate_limit
    )
    return response


class Limiter:
    """
    Initializes the slowapi rate limiter.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…