From dc2342859eb77de633980a2512d18a30edce2c0c Mon Sep 17 00:00:00 2001 From: Greg Price Date: Fri, 30 May 2014 13:22:57 -0400 Subject: [PATCH] Improve handling of bad JSON from comments service Instead of allowing the JSONDecodeError to escape, raise an error indicating the request id and containing the first 100 characters of the response to aid investigation. --- lms/lib/comment_client/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lms/lib/comment_client/utils.py b/lms/lib/comment_client/utils.py index 933ad62820..387163231b 100644 --- a/lms/lib/comment_client/utils.py +++ b/lms/lib/comment_client/utils.py @@ -104,7 +104,15 @@ def perform_request(method, url, data_or_params=None, raw=False, if raw: return response.text else: - data = response.json() + try: + data = response.json() + except ValueError: + raise CommentClientError( + u"Comments service returned invalid JSON for request {request_id}; first 100 characters: '{content}'".format( + request_id=request_id, + content=response.text[:100] + ) + ) if paged_results: dog_stats_api.histogram( 'comment_client.request.paged.result_count',