diff --git a/cybsi/cloud/error.py b/cybsi/cloud/error.py index fcca644..882ba4b 100644 --- a/cybsi/cloud/error.py +++ b/cybsi/cloud/error.py @@ -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 diff --git a/cybsi/cloud/internal/connector.py b/cybsi/cloud/internal/connector.py index aa4ea51..454f026 100644 --- a/cybsi/cloud/internal/connector.py +++ b/cybsi/cloud/internal/connector.py @@ -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 @@ -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