Skip to content

Commit aaab26a

Browse files
committed
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
1 parent 303e963 commit aaab26a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

tornado/simple_httpclient.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ def cleanup(self):
328328

329329
def _on_close(self):
330330
if self.final_callback is not None:
331-
raise HTTPError(599, "Connection closed")
331+
message = "Connection closed"
332+
if self.stream.error:
333+
message = str(self.stream.error)
334+
raise HTTPError(599, message)
332335

333336
def _on_headers(self, data):
334337
data = native_str(data.decode("latin1"))

tornado/test/simple_httpclient_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ def test_host_header(self):
283283
response = self.wait()
284284
self.assertTrue(host_re.match(response.body), response.body)
285285

286+
def test_connection_refused(self):
287+
self.http_client.fetch("http://localhost:1/", self.stop)
288+
response = self.wait()
289+
self.assertEqual(599, response.code)
290+
self.assertIn("Connection refused", str(response.error))
291+
286292

287293
class CreateAsyncHTTPClientTestCase(AsyncTestCase, LogTrapTestCase):
288294
def setUp(self):

0 commit comments

Comments
 (0)