]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
simple_httpclient: Report errno and reason for connection errors. 577/head
authorEvan Jones <ej@evanjones.ca>
Thu, 2 Aug 2012 15:13:58 +0000 (11:13 -0400)
committerEvan Jones <ej@evanjones.ca>
Thu, 2 Aug 2012 15:13:58 +0000 (11:13 -0400)
Previously, this reported "Connection closed" for everything. This change
adds the exception info: HTTP 599: [Errno 61] Connection refused

tornado/simple_httpclient.py
tornado/test/simple_httpclient_test.py

index c6e8a3a7ce0e0594d725cf5a09571651ab69b779..5edc4189adceab744987c93fdc8569d171b1da74 100644 (file)
@@ -328,7 +328,10 @@ class _HTTPConnection(object):
 
     def _on_close(self):
         if self.final_callback is not None:
-            raise HTTPError(599, "Connection closed")
+            message = "Connection closed"
+            if self.stream.error:
+                message = str(self.stream.error)
+            raise HTTPError(599, message)
 
     def _on_headers(self, data):
         data = native_str(data.decode("latin1"))
index 237a30f894b6fce22b6b94ca1f6efe14017c8bea..e035647b0d2ed619c4a7d1e187764c10c0472908 100644 (file)
@@ -283,6 +283,12 @@ class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase):
         response = self.wait()
         self.assertTrue(host_re.match(response.body), response.body)
 
+    def test_connection_refused(self):
+        self.http_client.fetch("http://localhost:1/", self.stop)
+        response = self.wait()
+        self.assertEqual(599, response.code)
+        self.assertIn("Connection refused", str(response.error))
+
 
 class CreateAsyncHTTPClientTestCase(AsyncTestCase, LogTrapTestCase):
     def setUp(self):