From aaab26a4438aa794b28ab7b7dc01eb7b65c698e1 Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Thu, 2 Aug 2012 11:13:58 -0400 Subject: [PATCH] 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 --- tornado/simple_httpclient.py | 5 ++++- tornado/test/simple_httpclient_test.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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): -- 2.47.2