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..3e8542da 100644 --- a/swaggerpy/exception.py +++ b/swaggerpy/exception.py @@ -19,7 +19,16 @@ 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 SwaggerRequestError(Exception): + """Generic exception that consumers of this package can catch""" + + +class TimeoutError(SwaggerRequestError): + """Error raised when the underlying crochet implementation + raises a TimeoutError"""