fix(aurweb): resolve exception in ratelimit

Redis's get() method can return None which makes an RPC request error
out:

  File "/srv/http/aurweb/aurweb/ratelimit.py", line 103, in check_ratelimit
    requests = int(requests.decode())
AttributeError: 'NoneType' object has no attribute 'decode'
This commit is contained in:
Jelle van der Waa 2022-08-14 15:43:13 +02:00
parent 4565aa38cf
commit 9497f6e671
No known key found for this signature in database
GPG key ID: C06086337C50773E

View file

@ -94,7 +94,7 @@ def check_ratelimit(request: Request):
# valid cache value will be returned which must be converted # valid cache value will be returned which must be converted
# to an int. Otherwise, use the database record returned # to an int. Otherwise, use the database record returned
# by update_ratelimit. # by update_ratelimit.
if not config.getboolean("ratelimit", "cache"): if not config.getboolean("ratelimit", "cache") or requests is None:
# If we got nothing from pipeline.get, we did not use # If we got nothing from pipeline.get, we did not use
# the Redis path of logic: use the DB record's count. # the Redis path of logic: use the DB record's count.
requests = record.Requests requests = record.Requests