mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-25 07:09:21 -04:00
Use parse_{int,str} and assert from http.servlet
parse_integer and parse_string can take a request and raise errors in case we have wrong or missing params. This PR tries to use them more to deduplicate some code and make it better readable
This commit is contained in:
parent
2aba1f549c
commit
32fd6910d0
14 changed files with 90 additions and 154 deletions
|
@ -18,8 +18,8 @@ import logging
|
|||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.api.errors import AuthError, Codes, SynapseError
|
||||
from synapse.http.servlet import parse_json_object_from_request
|
||||
from synapse.api.errors import AuthError, SynapseError
|
||||
from synapse.http.servlet import assert_params_in_request, parse_json_object_from_request
|
||||
from synapse.types import RoomAlias
|
||||
|
||||
from .base import ClientV1RestServlet, client_path_patterns
|
||||
|
@ -52,15 +52,14 @@ class ClientDirectoryServer(ClientV1RestServlet):
|
|||
|
||||
@defer.inlineCallbacks
|
||||
def on_PUT(self, request, room_alias):
|
||||
room_alias = RoomAlias.from_string(room_alias)
|
||||
|
||||
content = parse_json_object_from_request(request)
|
||||
if "room_id" not in content:
|
||||
raise SynapseError(400, "Missing room_id key",
|
||||
raise SynapseError(400, 'Missing params: ["room_id"]',
|
||||
errcode=Codes.BAD_JSON)
|
||||
|
||||
logger.debug("Got content: %s", content)
|
||||
|
||||
room_alias = RoomAlias.from_string(room_alias)
|
||||
|
||||
logger.debug("Got room name: %s", room_alias.to_string())
|
||||
|
||||
room_id = content["room_id"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue