mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 23:14:56 -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
|
@ -128,14 +128,21 @@ def parse_json_object_from_request(request):
|
|||
if it wasn't a JSON object.
|
||||
"""
|
||||
try:
|
||||
content = simplejson.loads(request.content.read())
|
||||
if type(content) != dict:
|
||||
message = "Content must be a JSON object."
|
||||
raise SynapseError(400, message, errcode=Codes.BAD_JSON)
|
||||
return content
|
||||
content_bytes = request.content.read()
|
||||
except:
|
||||
raise SynapseError(400, "Error reading JSON content.")
|
||||
|
||||
try:
|
||||
content = simplejson.loads(content_bytes)
|
||||
except simplejson.JSONDecodeError:
|
||||
raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)
|
||||
|
||||
if type(content) != dict:
|
||||
message = "Content must be a JSON object."
|
||||
raise SynapseError(400, message, errcode=Codes.BAD_JSON)
|
||||
|
||||
return content
|
||||
|
||||
|
||||
class RestServlet(object):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue