Skip to content

Commit

Permalink
Error handling here, too
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeBishop committed May 15, 2024
1 parent c65043a commit 4b0b972
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/TWCManager/Vehicle/TeslaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -1403,14 +1403,22 @@ def get_car_api(self, url, checkReady=True, provesOnline=True):
for _ in range(0, 3):
try:
req = requests.get(url, headers=headers, verify=self.verifyCert)
req.raise_for_status()
logger.log(logging.INFO8, "Car API cmd " + url + " " + str(req))
apiResponseDict = json.loads(req.text)
# This error can happen here as well:
# {'response': {'reason': 'could_not_wake_buses', 'result': False}}
# This one is somewhat common:
# {'response': None, 'error': 'vehicle unavailable: {:error=>"vehicle unavailable:"}', 'error_description': ''}
except requests.exceptions.RequestException:
pass
if req.status_code == 401 and "expired" in req.text:
# If the token is expired, refresh it and try again
self.apiRefresh()
continue
elif req.status_code == 429:
# We're explicitly being told to back off
self.errorCount = max(30, self.errorCount)
return False, None
except json.decoder.JSONDecodeError:
pass

Expand Down

0 comments on commit 4b0b972

Please sign in to comment.