Skip to content

Commit 456684b

Browse files
authored
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"
1 parent a72bcc6 commit 456684b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

docs/index.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ $ pip install slowapi
2727
limiter = Limiter(key_func=get_remote_address)
2828
app = Starlette()
2929
app.state.limiter = limiter
30-
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
30+
@app.exception_handler(RateLimitExceeded)
31+
def rate_limit_exceeded_handler(request: Request, exc: RateLimitExceeded) -> Response:
32+
return _rate_limit_exceeded_handler(request, exc)
3133

3234
@limiter.limit("5/minute")
3335
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
4951
limiter = Limiter(key_func=get_remote_address)
5052
app = FastAPI()
5153
app.state.limiter = limiter
52-
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
54+
@app.exception_handler(RateLimitExceeded)
55+
def rate_limit_exceeded_handler(request: Request, exc: RateLimitExceeded) -> Response:
56+
return _rate_limit_exceeded_handler(request, exc)
5357

5458
# Note: the route decorator must be above the limit decorator, not below it
5559
@app.get("/home")

0 commit comments

Comments
 (0)