PowerBI: catch outdated token (#6634)

This adds just a small tweak to catch the error that says the token is
expired rather then retrying.
This commit is contained in:
Eduard van Valkenburg 2023-06-24 00:01:08 +02:00 committed by GitHub
parent b1de927f1b
commit 48381f1f78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -96,6 +96,11 @@ class QueryPowerBITool(BaseTool):
logger.info("Query: %s", query)
pbi_result = self.powerbi.run(command=query)
result, error = self._parse_output(pbi_result)
if error is not None and "TokenExpired" in error:
self.session_cache[
tool_input
] = "Authentication token expired or invalid, please try reauthenticate."
return self.session_cache[tool_input]
iterations = kwargs.get("iterations", 0)
if error and iterations < self.max_iterations:
@ -140,6 +145,11 @@ class QueryPowerBITool(BaseTool):
logger.info("Query: %s", query)
pbi_result = await self.powerbi.arun(command=query)
result, error = self._parse_output(pbi_result)
if error is not None and "TokenExpired" in error:
self.session_cache[
tool_input
] = "Authentication token expired or invalid, please try reauthenticate."
return self.session_cache[tool_input]
iterations = kwargs.get("iterations", 0)
if error and iterations < self.max_iterations:

View File

@ -226,7 +226,7 @@ class PowerBIDataset(BaseModel):
json=self._create_json_content(command),
timeout=10,
) as response:
response_json = await response.json()
response_json = await response.json(content_type=response.content_type)
return response_json
async with aiohttp.ClientSession() as session:
async with session.post(
@ -235,7 +235,7 @@ class PowerBIDataset(BaseModel):
json=self._create_json_content(command),
timeout=10,
) as response:
response_json = await response.json()
response_json = await response.json(content_type=response.content_type)
return response_json