|
1 | 1 | from logging import Logger |
2 | 2 | from typing import Optional, Callable, Dict, Any, List |
3 | 3 |
|
4 | | -from slack_sdk.errors import SlackApiError |
| 4 | +from slack_sdk.errors import SlackApiError, SlackTokenRotationError |
5 | 5 | from slack_sdk.oauth import InstallationStore |
6 | 6 | from slack_sdk.oauth.installation_store.models.bot import Bot |
7 | 7 | from slack_sdk.oauth.installation_store.models.installation import Installation |
@@ -271,6 +271,11 @@ def __call__( |
271 | 271 | user_token = refreshed.user_token |
272 | 272 | user_scopes = refreshed.user_scopes |
273 | 273 |
|
| 274 | + except SlackTokenRotationError as rotation_error: |
| 275 | + # When token rotation fails, it is usually unrecoverable |
| 276 | + # So, this built-in middleware gives up continuing with the following middleware and listeners |
| 277 | + self.logger.error(f"Failed to rotate tokens due to {rotation_error}") |
| 278 | + return None |
274 | 279 | except NotImplementedError as _: |
275 | 280 | self.find_installation_available = False |
276 | 281 |
|
@@ -304,6 +309,11 @@ def __call__( |
304 | 309 | bot_token = refreshed.bot_token |
305 | 310 | bot_scopes = refreshed.bot_scopes |
306 | 311 |
|
| 312 | + except SlackTokenRotationError as rotation_error: |
| 313 | + # When token rotation fails, it is usually unrecoverable |
| 314 | + # So, this built-in middleware gives up continuing with the following middleware and listeners |
| 315 | + self.logger.error(f"Failed to rotate tokens due to {rotation_error}") |
| 316 | + return None |
307 | 317 | except NotImplementedError as _: |
308 | 318 | self.find_bot_available = False |
309 | 319 | except Exception as e: |
|
0 commit comments