Skip to content

Commit

Permalink
log some error with error 500
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuen Lee committed Dec 24, 2023
1 parent 3fc1076 commit f1d243b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions custom_components/polestar_api/pypolestar/polestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ async def get_ev_data(self, vin: str):
if self.auth.token_expiry < datetime.now():
await self.auth.get_token()
except PolestarAuthException as e:
self.latest_call_code = 500
_LOGGER.exception("Auth Exception: %s", str(e))
self.updating = False
return
Expand All @@ -123,13 +124,15 @@ async def get_ev_data(self, vin: str):
except PolestarNotAuthorizedException:
await self.auth.get_token()
except PolestarApiException as e:
self.latest_call_code = 500
_LOGGER.warning('Failed to get Odo Meter data %s', str(e))

try:
await self._get_battery_data(vin)
except PolestarNotAuthorizedException:
await self.auth.get_token()
except PolestarApiException as e:
self.latest_call_code = 500
_LOGGER.exception('Failed to get Battery data %s', str(e))

self.updating = False
Expand Down Expand Up @@ -168,8 +171,13 @@ async def get_graph_ql(self, params: dict):
f"Get GraphQL error: {result.text}")
resultData = result.json()
# if we get result with errors and with message "user is not authorized" then we throw an exception
if resultData.get('errors') and resultData['errors'][0]['message'] == "User is not authorized":
raise PolestarNotAuthorizedException("Unauthorized Exception")
if resultData.get('errors'):
# we get 200 but if there is error, then we should have an internal error
self.latest_call_code = 500
if resultData['errors'][0]['message'] == "User is not authorized":
raise PolestarNotAuthorizedException("Unauthorized Exception")
# otherwise log the error
_LOGGER.error(resultData['errors'][0]['message'])

_LOGGER.debug(resultData)
return resultData

0 comments on commit f1d243b

Please sign in to comment.