]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Update example for HTTPClient exception handling.
authorBen Darnell <ben@bendarnell.com>
Mon, 15 Sep 2014 03:55:59 +0000 (23:55 -0400)
committerBen Darnell <ben@bendarnell.com>
Mon, 15 Sep 2014 03:55:59 +0000 (23:55 -0400)
Eliminate the implication that HTTPError is the only
error that can be raised.  See #1168.

tornado/httpclient.py

index c8ecf47c317b0f0fd35ade5efa9e48c7c7f61119..df4295171eec8de6efdeed2bd29b9abcd8aaa89a 100644 (file)
@@ -63,7 +63,12 @@ class HTTPClient(object):
             response = http_client.fetch("http://www.google.com/")
             print response.body
         except httpclient.HTTPError as e:
-            print "Error:", e
+            # HTTPError is raised for non-200 responses; the response
+            # can be found in e.response.
+            print("Error: " + str(e))
+        except Exception as e:
+            # Other errors are possible, such as IOError.
+            print("Error: " + str(e))
         http_client.close()
     """
     def __init__(self, async_client_class=None, **kwargs):