Skip to content

Commit

Permalink
throwing a timeout error when the underlying crochet impl raises time…
Browse files Browse the repository at this point in the history
…out errors
  • Loading branch information
KurtisFreedland committed Sep 16, 2014
1 parent 7a435c2 commit 1cc4527
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions swaggerpy/async_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 10 additions & 1 deletion swaggerpy/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

0 comments on commit 1cc4527

Please sign in to comment.