Skip to content

Commit

Permalink
fix(api-client): Fixed api client to handle graphql errors
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Jun 25, 2023
1 parent 34ef0e8 commit 78414d2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion custom_components/octopus_energy/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 78414d2

Please sign in to comment.