Skip to content

Commit

Permalink
Fixed potencial stackoverflow
Browse files Browse the repository at this point in the history
  • Loading branch information
guerrerotook committed Apr 27, 2024
1 parent 25cec96 commit 6eec9e1
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions custom_components/securitas/securitas_direct_new_api/apimanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,31 +179,23 @@ async def _execute_request(

async def _check_errros(self, value: str) -> bool:
if value is not None:
try:
response = json.loads(value)
if "errors" in response:
for error_item in response["errors"]:
if "message" in error_item:
if (
error_item["message"]
== "Invalid session. Please, try again later."
or error_item["message"] == "Invalid token: Expired"
or error_item["message"]
== "Required request header 'x-installationNumber' for method parameter type String is not present"
):
self.authentication_token = None
_LOGGER.info("Login is expired. Login again")
await self.login()
return True
else:
_LOGGER.error(error_item["message"])
except Exception as error:
_LOGGER.error(value)
_LOGGER.error(error)
if "Request unsuccessful. Incapsula incident ID" in value:
self.authentication_token = None
_LOGGER.info("Login is expired. Login again")
await self.login()
response = json.loads(value)
if "errors" in response:
for error_item in response["errors"]:
if "message" in error_item:
if (
error_item["message"]
== "Invalid session. Please, try again later."
or error_item["message"] == "Invalid token: Expired"
or error_item["message"]
== "Required request header 'x-installationNumber' for method parameter type String is not present"
):
self.authentication_token = None
_LOGGER.info("Login is expired. Login again")
await self.login()
return True
else:
_LOGGER.error(error_item["message"])
return False

async def _check_capabilities_token(self, installation: Installation) -> None:
Expand Down

0 comments on commit 6eec9e1

Please sign in to comment.