diff --git a/cybsi/api/error.py b/cybsi/api/error.py index 3043d9e..20d7c05 100644 --- a/cybsi/api/error.py +++ b/cybsi/api/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/api/internal/connector.py b/cybsi/api/internal/connector.py index 6ec6b2c..43a91b6 100644 --- a/cybsi/api/internal/connector.py +++ b/cybsi/api/internal/connector.py @@ -102,6 +102,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 @@ -197,6 +201,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