From 78414d2ddf19afea0f55fda59f702d59feb33347 Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Sun, 25 Jun 2023 16:29:45 +0100 Subject: [PATCH] fix(api-client): Fixed api client to handle graphql errors --- custom_components/octopus_energy/api_client.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/custom_components/octopus_energy/api_client.py b/custom_components/octopus_energy/api_client.py index 966a1b42..9466d22a 100644 --- a/custom_components/octopus_energy/api_client.py +++ b/custom_components/octopus_energy/api_client.py @@ -833,7 +833,15 @@ async def __async_read_response__(self, response, url): raise RequestError(msg) return None + data_as_json = None try: - return json.loads(text) + data_as_json = json.loads(text) except: raise Exception(f'Failed to extract response json: {url}; {text}') + + if ("graphql" in url and "errors" in data_as_json): + msg = f'Errors in request ({url}): {data_as_json["errors"]}' + _LOGGER.debug(msg) + raise RequestError(msg) + + return data_as_json