From 2fd94c5e6317478273b88ec55f29a36544a25f09 Mon Sep 17 00:00:00 2001
From: Tim Abbott <tabbott@humbughq.com>
Date: Mon, 29 Jul 2013 18:02:28 -0400
Subject: [PATCH] api: Fix error reporting when result is not JSON.

Previously, we would return a JSONDecodeError to the user in the event
that the server returned a 500 error (or other non-JSON content).

(imported from commit 1624dfec6ac65d34216f4de91e33116a54e414fa)
---
 humbug/__init__.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/humbug/__init__.py b/humbug/__init__.py
index 1b0750ec..1512a6e5 100644
--- a/humbug/__init__.py
+++ b/humbug/__init__.py
@@ -187,15 +187,19 @@ class Client(object):
                 return {'msg': "Unexpected error:\n%s" % traceback.format_exc(),
                         "result": "unexpected-error"}
 
-            if requests_json_is_function:
-                json_result = res.json()
-            else:
-                json_result = res.json
+            try:
+                if requests_json_is_function:
+                    json_result = res.json()
+                else:
+                    json_result = res.json
+            except Exception:
+                json_result = None
+
             if json_result is not None:
                 end_error_retry(True)
                 return json_result
             end_error_retry(False)
-            return {'msg': res.text, "result": "http-error",
+            return {'msg': "Unexpected error from the server", "result": "http-error",
                     "status_code": res.status_code}
 
     @classmethod