From 4bc1799d102d1791bd7ccc3bb9f6e63eaec52b4b Mon Sep 17 00:00:00 2001 From: Kurtis Freedland Date: Tue, 16 Sep 2014 12:18:59 -0700 Subject: [PATCH] throwing a timeout error when the underlying crochet impl raises timeout errors --- swaggerpy/async_http_client.py | 7 +++++-- swaggerpy/exception.py | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/swaggerpy/async_http_client.py b/swaggerpy/async_http_client.py index 93093b73..3004f567 100644 --- a/swaggerpy/async_http_client.py +++ b/swaggerpy/async_http_client.py @@ -18,6 +18,7 @@ import twisted.web.client from swaggerpy import http_client from swaggerpy.exception import HTTPError +from swaggerpy.exception import TimeoutError from swaggerpy.multipart_response import create_multipart_content from twisted.internet import reactor from twisted.internet.defer import Deferred @@ -75,8 +76,10 @@ def wait(self, timeout): log.info(u"%s %s", self.request_params.get('method'), self.request_params.get('uri')) # finished_resp is returned here - # TODO: catch known exceptions and raise common exceptions - return self.eventual.wait(timeout) + try: + return self.eventual.wait(timeout) + except crochet._eventloop.TimeoutError as e: + raise TimeoutError(e) @crochet.run_in_reactor def fetch_deferred(self): diff --git a/swaggerpy/exception.py b/swaggerpy/exception.py index f73d4b5b..370966e8 100644 --- a/swaggerpy/exception.py +++ b/swaggerpy/exception.py @@ -19,7 +19,12 @@ def __init__(self, *args, **kwargs): super(HTTPError, self).__init__(*args, **kwargs) -class CancelledError(): +class CancelledError(Exception): """Error raised when result() is called from HTTPFuture and call was actually cancelled """ + + +class TimeoutError(Exception): + """Error raised when the underlying crochet implementation + raises a TimeoutError"""