Skip to content
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
4 changes: 2 additions & 2 deletions kanboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions tests/test_kanboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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""
Expand All @@ -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}'
Expand Down