def _parse_and_update_body(self, handler_def):
"""Parses the request body to JSON."""
if self.request.body:
try:
json_body = json.loads(self.request.body.decode('utf-8'))
except json.JSONDecodeError:
raise BadRequestError(
"Malformed request body. JSON is expected."
)
new_body = json_body
if handler_def.consumes:
try:
new_body = handler_def.consumes.from_json(json_body)
except ValidationError:
# TODO: log warning or error
raise BadRequestError("Bad data structure.")
self.request.body = new_body
评论列表
文章目录