Return more informations about bad requests for crash reports

This commit is contained in:
Julien Duponchelle 2015-04-09 10:22:25 +02:00
parent 2b6945664b
commit 1d997d9da5

View File

@ -40,6 +40,7 @@ def parse_request(request, input_schema):
try:
request.json = json.loads(body.decode('utf-8'))
except ValueError as e:
request.json = {"malformed_json": body.decode('utf-8')}
raise aiohttp.web.HTTPBadRequest(text="Invalid JSON {}".format(e))
else:
request.json = {}
@ -137,6 +138,10 @@ class Route(object):
log.warn("Could not write to the record file {}: {}".format(record_file, e))
response = Response(route=route, output_schema=output_schema)
yield from func(request, response)
except aiohttp.web.HTTPBadRequest as e:
response = Response(route=route)
response.set_status(e.status)
response.json({"message": e.text, "status": e.status, "path": route, "request": request.json})
except aiohttp.web.HTTPException as e:
response = Response(route=route)
response.set_status(e.status)