Skip to content

Commit

Permalink
Fix empty exception message when timeout occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
pvragov authored and perastov committed Sep 26, 2023
1 parent 4052fff commit eb7d468
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit eb7d468

Please sign in to comment.