return 400 on invalid json post data

This commit is contained in:
Raphael Deem
2016-12-07 20:33:56 -08:00
parent 3ea1a80496
commit 457507d8dc
2 changed files with 15 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ from http.cookies import SimpleCookie
from httptools import parse_url
from urllib.parse import parse_qs
from ujson import loads as json_loads
from sanic.exceptions import InvalidUsage
from .log import log
@@ -67,7 +68,7 @@ class Request(dict):
try:
self.parsed_json = json_loads(self.body)
except Exception:
log.exception("Failed when parsing body as json")
raise InvalidUsage("Failed when parsing body as json")
return self.parsed_json