Browse Source

Improved exception handling across httplib versions

Alois Mahdal 11 years ago
parent
commit
14cc12ef4c
1 changed files with 13 additions and 4 deletions
  1. 13
    4
      lib/htlogr.py

+ 13
- 4
lib/htlogr.py View File

@@ -57,10 +57,19 @@ class htlogr:
57 57
         params = {"msg": msg, "tag": tag, "i": i}
58 58
         pq = "%s?%s" % (self.parsed_url.path, self._zipup_params(params))
59 59
         self.conn.request("GET", pq)
60
-        r = self.conn.getresponse()
61
-        assert r.status == 200, ("logging server returned error %s,"
62
-                                 "message not logged" % r.status)
63
-        return r.read()
60
+        return_msg = None
61
+        try:
62
+            r = self.conn.getresponse()
63
+            assert r.status == 200, ("logging server returned error %s,"
64
+                                     "message not logged" % r.status)
65
+            return_msg = r.read()
66
+        except httplib.BadStatusLine as e:
67
+            return_msg = ("httplib does not like thie line:\n\n    %s"
68
+                          % e.line)
69
+        except:
70
+            return_msg = ("something bad happened. We don't know what"
71
+                          " but we know it's bad")
72
+        return return_msg
64 73
 
65 74
     def data(self, data, tag=None, i=None):
66 75
         assert isinstance(data, dict), "data must be dict"