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

Fix empty exception message when timeout occurs #5

Merged
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: 4 additions & 3 deletions cybsi/cloud/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ class CybsiError(Exception):

"""

def __init__(self, message, ex: Optional[Exception] = None):
msg = message if ex is None else f"{message}: {ex}"
super().__init__(msg)
def __init__(self, message: str, ex: Optional[Exception] = None):
if ex and str(ex) != "":
message = f"{message}: {ex}"
super().__init__(message)
self._ex = ex


Expand Down
8 changes: 8 additions & 0 deletions cybsi/cloud/internal/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def _do(self, method: str, path: str, stream=False, **kwargs):
resp = self._client.send(request=req, stream=stream)
except CybsiError:
raise
except httpx.TimeoutException as exp:
# Handle httpx.TimeoutException separately
# because it doesn't have an exception message.
raise CybsiError("request timeout", exp) from exp
except Exception as exp:
raise CybsiError("could not send request", exp) from exp

Expand Down Expand Up @@ -195,6 +199,10 @@ async def _do(self, method: str, path: str, stream=False, **kwargs):
resp = await self._client.send(request=req, stream=stream)
except CybsiError:
raise
except httpx.TimeoutException as exp:
# Handle httpx.TimeoutException separately
# because it doesn't have an exception message.
raise CybsiError("request timeout", exp) from exp
except Exception as exp:
raise CybsiError("could not send request", exp) from exp

Expand Down