From: Evan Jones Date: Thu, 2 Aug 2012 15:13:58 +0000 (-0400) Subject: simple_httpclient: Report errno and reason for connection errors. X-Git-Tag: v2.4.0~20^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aaab26a4438aa794b28ab7b7dc01eb7b65c698e1;p=thirdparty%2Ftornado.git 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 --- diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index c6e8a3a7c..5edc4189a 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -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")) diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index 237a30f89..e035647b0 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -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):