a84b469437f0 — Steve Fink 4 years ago
Log malformed JSON responses
1 files changed, 10 insertions(+), 1 deletions(-)

M bzauth.py
M bzauth.py +10 -1
@@ 150,7 150,16 @@ class bzAuth:
 
         res = self.session.request(method, url, data=data, **kwargs)
 
-        j = res.json()
+        try:
+            j = res.json()
+        except json.JSONDecodeError:
+            # For debugging, save out the raw response. This should not happen.
+            outfile = "/tmp/bzauth.debug.txt"
+            with open(outfile, "wb") as fh:
+                fh.write(res.content)
+            print("Wrote {}".format(outfile))
+            raise
+
         if 'error' in j:
             raise Exception('REST error on %s to %s: %s' % (
                 method, url, j['message']))