Skip to content

Commit

Permalink
Catch exceptions when json.loads() in view
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgreig committed Nov 29, 2016
1 parent 3703d06 commit 63c6e5b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion habitat/views/payload_telemetry.py
Expand Up @@ -259,7 +259,10 @@ def add_listener_update(doc, req):
returned) or because of a save conflict. In the event of a save conflict,
uploaders should retry the same request until the conflict is resolved.
"""
protodoc = json.loads(req["body"])
try:
protodoc = json.loads(req["body"])
except ValueError:
raise ForbiddenError("invalid JSON")
if "data" not in protodoc or "_raw" not in protodoc["data"]:
raise ForbiddenError("doc.data._raw is required")
if "receivers" not in protodoc or len(protodoc["receivers"]) != 1:
Expand Down

0 comments on commit 63c6e5b

Please sign in to comment.