Skip to content

Commit

Permalink
json_body: read the bodyfile from the beginning.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauritsvanrees committed Nov 2, 2023
1 parent 5bc5145 commit 617d443
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/plone/restapi/deserializer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@


def json_body(request):
try:
bodyfile = request.get("BODYFILE")
data = {} if bodyfile is None else json.load(bodyfile)
except ValueError:
raise DeserializationError("No JSON object could be decoded")
bodyfile = request.get("BODYFILE")
if bodyfile is None:
data = {}
else:
if bodyfile.tell() != 0:
# Something has already read the bodyfile.
# Go back to the beginning.
bodyfile.seek(0)
try:
data = json.load(bodyfile)
except ValueError:
breakpoint()
raise DeserializationError("No JSON object could be decoded")
if not isinstance(data, dict):
raise DeserializationError("Malformed body")
return data
Expand Down

0 comments on commit 617d443

Please sign in to comment.