mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-03-06 13:35:53 -05:00
client: Error out gracefully if we get an invalid limit.
This commit is contained in:
parent
ba09f77cb6
commit
fe10f54ea9
@ -103,6 +103,8 @@ class UnknownRoomError(Exception):
|
||||
class InvalidOrderByError(Exception):
|
||||
pass
|
||||
|
||||
class InvalidLimit(Exception):
|
||||
pass
|
||||
|
||||
class PanClient(AsyncClient):
|
||||
"""A wrapper class around a nio AsyncClient extending its functionality."""
|
||||
@ -717,6 +719,10 @@ class PanClient(AsyncClient):
|
||||
term = search_terms["search_term"]
|
||||
search_filter = search_terms["filter"]
|
||||
limit = search_filter.get("limit", 10)
|
||||
|
||||
if limit <= 0:
|
||||
raise InvalidLimit(f"The limit must be strictly greater than 0.")
|
||||
|
||||
order_by = search_terms.get("order_by")
|
||||
|
||||
if order_by not in ["rank", "recent"]:
|
||||
|
@ -28,7 +28,8 @@ from multidict import CIMultiDict
|
||||
from nio import (Api, EncryptionError, LoginResponse, OlmTrustError,
|
||||
SendRetryError)
|
||||
|
||||
from pantalaimon.client import InvalidOrderByError, PanClient, UnknownRoomError
|
||||
from pantalaimon.client import (InvalidOrderByError, PanClient,
|
||||
UnknownRoomError, InvalidLimit)
|
||||
from pantalaimon.log import logger
|
||||
from pantalaimon.store import ClientInfo, PanStore
|
||||
from pantalaimon.thread_messages import (AcceptSasMessage, CancelSasMessage,
|
||||
@ -942,7 +943,7 @@ class ProxyDaemon:
|
||||
},
|
||||
status=400,
|
||||
)
|
||||
except InvalidOrderByError as e:
|
||||
except (InvalidOrderByError, InvalidLimit) as e:
|
||||
return web.json_response(
|
||||
{
|
||||
"errcode": "M_INVALID_PARAM",
|
||||
|
Loading…
x
Reference in New Issue
Block a user