From 20be91b496e03617c9bfa7c94ba8876fe8e89231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20L=C3=B3pez?= Date: Sat, 14 May 2022 12:44:28 +0200 Subject: [PATCH] Added exceptions with debugging information for historical requests --- ideenergy/client.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ideenergy/client.py b/ideenergy/client.py index 1610e59..f165c34 100644 --- a/ideenergy/client.py +++ b/ideenergy/client.py @@ -384,10 +384,20 @@ def _generation_parser(data) -> Dict[str, Any]: ) resp = await self.raw_request("GET", url) buff = await resp.content.read() - buff = buff.decode(resp.charset) - data = json.loads(buff) - return parser(data) + try: + buff = buff.decode(resp.charset) + data = json.loads(buff) + + return parser(data) + + except (TypeError, json.JSONDecodeError) as e: + raise InvalidData(buff) from e + + except NotImplementedError as e: + raise NotImplementedError( + f"Request type not implemented: {req_type}. server data: {buff!r}" + ) from e class ClientError(Exception):