refactor: improve error handling for Slack token refresh logic

- Updated SlackHistory class to enforce the use of session and connector_id for token refresh, raising a ValueError for legacy token usage.
- Simplified conditional checks for client initialization in SlackHistory.
- Cleaned up unnecessary comments and whitespace in the codebase.
This commit is contained in:
Anish Sarkar 2026-01-04 02:47:50 +05:30
parent 81e4a4ada0
commit 1862732913
3 changed files with 13 additions and 12 deletions

View file

@ -65,19 +65,23 @@ class SlackHistory:
"""
# If we have a direct token (backward compatibility), use it
# Check if client was initialized with a token directly (not via credentials)
if self.client and self._session is None and self._connector_id is None:
if (
self.client
and self._session is None
and self._connector_id is None
and self._credentials is None
):
# This means it was initialized with a direct token, extract it
# WebClient stores token internally, we need to get it from the client
# For backward compatibility, we'll use the client directly
# But we can't easily extract the token, so we'll just use the client
# In this case, we'll skip refresh logic
if self._credentials is None:
# This is the old pattern - just use the client as-is
# We can't extract token easily, so we'll raise an error
# asking to use the new pattern
raise ValueError(
"Cannot refresh token: Please use session and connector_id for auto-refresh support"
)
# This is the old pattern - just use the client as-is
# We can't extract token easily, so we'll raise an error
# asking to use the new pattern
raise ValueError(
"Cannot refresh token: Please use session and connector_id for auto-refresh support"
)
# Load credentials from DB if not provided
if self._credentials is None:

View file

@ -73,4 +73,3 @@ class SlackAuthCredentialsBase(BaseModel):
if isinstance(v, datetime):
return v if v.tzinfo else v.replace(tzinfo=UTC)
return v

View file

@ -103,9 +103,7 @@ async def index_slack_messages(
)
# Use the new pattern with session and connector_id for auto-refresh
slack_client = SlackHistory(
session=session, connector_id=connector_id
)
slack_client = SlackHistory(session=session, connector_id=connector_id)
# Handle 'undefined' string from frontend (treat as None)
if start_date == "undefined" or start_date == "":