diff --git a/kanboard.py b/kanboard.py index 1a0c45d..8076031 100644 --- a/kanboard.py +++ b/kanboard.py @@ -145,8 +145,9 @@ def _parse_response(response: bytes) -> Any: try: body = json.loads(response.decode(errors="ignore")) - if "error" in body: - message = body.get("error").get("message") + error = body.get("error") + if error: + message = error.get("message") if isinstance(error, dict) else str(error) raise ClientError(message) return body.get("result") diff --git a/tests/test_kanboard.py b/tests/test_kanboard.py index 9f77eed..e03118f 100644 --- a/tests/test_kanboard.py +++ b/tests/test_kanboard.py @@ -83,6 +83,13 @@ def test_application_error(self): with self.assertRaises(kanboard.ClientError, msg="Internal error"): self.client.remote_procedure() + def test_application_error_non_dict(self): + body = b'{"jsonrpc": "2.0", "error": "Something went wrong", "id": 123}' + self.urlopen.return_value.read.return_value = body + + with self.assertRaises(kanboard.ClientError, msg="Something went wrong"): + self.client.remote_procedure() + def test_async_method_call_recognised(self): method_name = "some_method_async" result = self.client.is_async_method_name(method_name)