Permalink
Browse files

simple_httpclient: Report errno and reason for connection errors.

Previously, this reported "Connection closed" for everything. This change
adds the exception info: HTTP 599: [Errno 61] Connection refused
  • Loading branch information...
1 parent 303e963 commit aaab26a4438aa794b28ab7b7dc01eb7b65c698e1 @evanj evanj committed Aug 2, 2012
Showing with 10 additions and 1 deletion.
  1. +4 −1 tornado/simple_httpclient.py
  2. +6 −0 tornado/test/simple_httpclient_test.py
@@ -328,7 +328,10 @@ def cleanup(self):
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"))
@@ -283,6 +283,12 @@ def test_host_header(self):
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):

0 comments on commit aaab26a

Please sign in to comment.