diff --git a/kanboard.py b/kanboard.py index 4f4dead..11fba93 100644 --- a/kanboard.py +++ b/kanboard.py @@ -166,7 +166,7 @@ def _parse_response(response: bytes) -> Any: return body.get("result") except ValueError as e: - raise ClientError(f"Failed to parse JSON response: {e}") + raise ClientError(f"Failed to parse JSON response: {e}") from e def _do_request(self, headers: Dict[str, str], body: Dict[str, Any]) -> Any: try: @@ -182,7 +182,7 @@ def _do_request(self, headers: Dict[str, str], body: Dict[str, Any]) -> Any: response = http.urlopen(request, context=ssl_context, timeout=self._timeout).read() except Exception as e: - raise ClientError(str(e)) + raise ClientError(str(e)) from e return self._parse_response(response) def execute(self, method: str, **kwargs: Any) -> Any: diff --git a/tests/test_kanboard.py b/tests/test_kanboard.py index 99fd187..0b4d61c 100644 --- a/tests/test_kanboard.py +++ b/tests/test_kanboard.py @@ -52,9 +52,11 @@ def test_custom_auth_header(self): assert kwargs["headers"]["X-Auth-Header"] == "dXNlcm5hbWU6cGFzc3dvcmQ=" def test_http_error(self): - self.urlopen.side_effect = Exception() - with self.assertRaises(kanboard.ClientError): + original = Exception("connection refused") + self.urlopen.side_effect = original + with self.assertRaises(kanboard.ClientError) as cm: self.client.remote_procedure() + self.assertIs(cm.exception.__cause__, original) def test_empty_response_raises_client_error(self): self.urlopen.return_value.read.return_value = b"" @@ -68,6 +70,7 @@ def test_json_parsing_failure(self): with self.assertRaises(kanboard.ClientError) as cm: self.client.remote_procedure() self.assertIn("Failed to parse JSON response", str(cm.exception)) + self.assertIsInstance(cm.exception.__cause__, ValueError) def test_application_error(self): body = b'{"jsonrpc": "2.0", "error": {"code": -32603, "message": "Internal error"}, "id": 123}'