mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-08 17:32:13 -04:00
Use parse_json_object_from_request to parse JSON out of request bodies
This commit is contained in:
parent
c081228439
commit
e9c1cabac2
11 changed files with 49 additions and 90 deletions
|
@ -15,15 +15,13 @@
|
|||
|
||||
from ._base import client_v2_patterns
|
||||
|
||||
from synapse.http.servlet import RestServlet
|
||||
from synapse.api.errors import AuthError, SynapseError
|
||||
from synapse.http.servlet import RestServlet, parse_json_object_from_request
|
||||
from synapse.api.errors import AuthError
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
import logging
|
||||
|
||||
import simplejson as json
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -47,11 +45,7 @@ class AccountDataServlet(RestServlet):
|
|||
if user_id != requester.user.to_string():
|
||||
raise AuthError(403, "Cannot add account data for other users.")
|
||||
|
||||
try:
|
||||
content_bytes = request.content.read()
|
||||
body = json.loads(content_bytes)
|
||||
except:
|
||||
raise SynapseError(400, "Invalid JSON")
|
||||
body = parse_json_object_from_request(request)
|
||||
|
||||
max_id = yield self.store.add_account_data_for_user(
|
||||
user_id, account_data_type, body
|
||||
|
@ -86,14 +80,7 @@ class RoomAccountDataServlet(RestServlet):
|
|||
if user_id != requester.user.to_string():
|
||||
raise AuthError(403, "Cannot add account data for other users.")
|
||||
|
||||
try:
|
||||
content_bytes = request.content.read()
|
||||
body = json.loads(content_bytes)
|
||||
except:
|
||||
raise SynapseError(400, "Invalid JSON")
|
||||
|
||||
if not isinstance(body, dict):
|
||||
raise ValueError("Expected a JSON object")
|
||||
body = parse_json_object_from_request(request)
|
||||
|
||||
max_id = yield self.store.add_account_data_to_room(
|
||||
user_id, room_id, account_data_type, body
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue