mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-03-08 22:45:55 -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):
|
class InvalidOrderByError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class InvalidLimit(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class PanClient(AsyncClient):
|
class PanClient(AsyncClient):
|
||||||
"""A wrapper class around a nio AsyncClient extending its functionality."""
|
"""A wrapper class around a nio AsyncClient extending its functionality."""
|
||||||
@ -717,6 +719,10 @@ class PanClient(AsyncClient):
|
|||||||
term = search_terms["search_term"]
|
term = search_terms["search_term"]
|
||||||
search_filter = search_terms["filter"]
|
search_filter = search_terms["filter"]
|
||||||
limit = search_filter.get("limit", 10)
|
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")
|
order_by = search_terms.get("order_by")
|
||||||
|
|
||||||
if order_by not in ["rank", "recent"]:
|
if order_by not in ["rank", "recent"]:
|
||||||
|
@ -28,7 +28,8 @@ from multidict import CIMultiDict
|
|||||||
from nio import (Api, EncryptionError, LoginResponse, OlmTrustError,
|
from nio import (Api, EncryptionError, LoginResponse, OlmTrustError,
|
||||||
SendRetryError)
|
SendRetryError)
|
||||||
|
|
||||||
from pantalaimon.client import InvalidOrderByError, PanClient, UnknownRoomError
|
from pantalaimon.client import (InvalidOrderByError, PanClient,
|
||||||
|
UnknownRoomError, InvalidLimit)
|
||||||
from pantalaimon.log import logger
|
from pantalaimon.log import logger
|
||||||
from pantalaimon.store import ClientInfo, PanStore
|
from pantalaimon.store import ClientInfo, PanStore
|
||||||
from pantalaimon.thread_messages import (AcceptSasMessage, CancelSasMessage,
|
from pantalaimon.thread_messages import (AcceptSasMessage, CancelSasMessage,
|
||||||
@ -942,7 +943,7 @@ class ProxyDaemon:
|
|||||||
},
|
},
|
||||||
status=400,
|
status=400,
|
||||||
)
|
)
|
||||||
except InvalidOrderByError as e:
|
except (InvalidOrderByError, InvalidLimit) as e:
|
||||||
return web.json_response(
|
return web.json_response(
|
||||||
{
|
{
|
||||||
"errcode": "M_INVALID_PARAM",
|
"errcode": "M_INVALID_PARAM",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user