From 2d86141a7042986a346b40a9154eef9da99d378b Mon Sep 17 00:00:00 2001 From: whoami Date: Wed, 9 Apr 2025 11:44:28 +0900 Subject: [PATCH] fix: Update index.md fix to the following type hint error: Parameter 2: type "Exception" is incompatible with type "RateLimitExceeded" "Exception" is not assignable to "RateLimitExceeded" --- docs/index.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 5ec4219..268171d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -27,7 +27,9 @@ $ pip install slowapi limiter = Limiter(key_func=get_remote_address) app = Starlette() app.state.limiter = limiter - app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) + @app.exception_handler(RateLimitExceeded) + def rate_limit_exceeded_handler(request: Request, exc: RateLimitExceeded) -> Response: + return _rate_limit_exceeded_handler(request, exc) @limiter.limit("5/minute") async def homepage(request: Request): @@ -49,7 +51,9 @@ The above app will have a route `t1` that will accept up to 5 requests per minut limiter = Limiter(key_func=get_remote_address) app = FastAPI() app.state.limiter = limiter - app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) + @app.exception_handler(RateLimitExceeded) + def rate_limit_exceeded_handler(request: Request, exc: RateLimitExceeded) -> Response: + return _rate_limit_exceeded_handler(request, exc) # Note: the route decorator must be above the limit decorator, not below it @app.get("/home")