summaryrefslogtreecommitdiff
path: root/cherrypy/lib/jsontools.py
diff options
context:
space:
mode:
authorAric Coady <aric.coady@gmail.com>2016-08-21 10:32:51 -0700
committerAric Coady <aric.coady@gmail.com>2016-09-03 13:37:28 -0700
commit244afb065adfa4f0530e4060f7328a71c8213882 (patch)
tree6b39ce78db90817964416eef1807b79c8d8acbd1 /cherrypy/lib/jsontools.py
parent54a18fa799cdbd4bf87726427b11bfb83872a4bd (diff)
downloadcherrypy-git-244afb065adfa4f0530e4060f7328a71c8213882.tar.gz
HTTPError provides context manager for handling exceptions.
Diffstat (limited to 'cherrypy/lib/jsontools.py')
-rw-r--r--cherrypy/lib/jsontools.py4
1 files changed, 1 insertions, 3 deletions
diff --git a/cherrypy/lib/jsontools.py b/cherrypy/lib/jsontools.py
index 79ceaa48..52f1f622 100644
--- a/cherrypy/lib/jsontools.py
+++ b/cherrypy/lib/jsontools.py
@@ -8,10 +8,8 @@ def json_processor(entity):
raise cherrypy.HTTPError(411)
body = entity.fp.read()
- try:
+ with cherrypy.HTTPError.handle(ValueError, 400, 'Invalid JSON document'):
cherrypy.serving.request.json = json_decode(body.decode('utf-8'))
- except ValueError:
- raise cherrypy.HTTPError(400, 'Invalid JSON document')
def json_in(content_type=[ntou('application/json'), ntou('text/javascript')],