feat: add authentication expiration handling for Notion tools

- Implemented checks for expired authentication in the Notion page creation and deletion tools, returning appropriate error messages for re-authentication.
- Updated the Notion tool metadata service to track account health and persist authentication status, improving error handling and user feedback during operations.
This commit is contained in:
Anish Sarkar 2026-03-20 16:12:18 +05:30
parent db5fddb104
commit 10af5d3f3e
3 changed files with 42 additions and 2 deletions

View file

@ -95,8 +95,19 @@ def create_delete_notion_page_tool(
"message": error_msg,
}
account = context.get("account", {})
if account.get("auth_expired"):
logger.warning(
"Notion account %s has expired authentication",
account.get("id"),
)
return {
"status": "auth_error",
"message": "The Notion account for this page needs re-authentication. Please re-authenticate in your connector settings.",
}
page_id = context.get("page_id")
connector_id_from_context = context.get("account", {}).get("id")
connector_id_from_context = account.get("id")
document_id = context.get("document_id")
logger.info(

View file

@ -110,6 +110,17 @@ def create_update_notion_page_tool(
"message": error_msg,
}
account = context.get("account", {})
if account.get("auth_expired"):
logger.warning(
"Notion account %s has expired authentication",
account.get("id"),
)
return {
"status": "auth_error",
"message": "The Notion account for this page needs re-authentication. Please re-authenticate in your connector settings.",
}
page_id = context.get("page_id")
document_id = context.get("document_id")
connector_id_from_context = context.get("account", {}).get("id")

View file

@ -167,8 +167,26 @@ class NotionToolMetadataService:
if not page_id:
return {"error": "Page ID not found in document metadata"}
acc_dict = account.to_dict()
auth_expired = await self._check_account_health(connector.id)
acc_dict["auth_expired"] = auth_expired
if auth_expired:
try:
db_connector = connector
if not db_connector.config.get("auth_expired"):
db_connector.config = {**db_connector.config, "auth_expired": True}
flag_modified(db_connector, "config")
await self._db_session.commit()
await self._db_session.refresh(db_connector)
except Exception:
logger.warning(
"Failed to persist auth_expired for connector %s",
connector.id,
exc_info=True,
)
return {
"account": account.to_dict(),
"account": acc_dict,
"page_id": page_id,
"current_title": document.title,
"document_id": document.id,