Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throwing a timeout error when the underlying crochet impl raises timeout #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"""