Exception for errors that should be communicated to the Slack user. This exception is caught by the centralized error handler in SlackManager, which logs the error and sends an appropriate message to the user. Usage: raise SlackError(SlackErrorCode.USER_NOT_AUTHENTICATED,
| 31 | |
| 32 | |
| 33 | class SlackError(Exception): |
| 34 | """Exception for errors that should be communicated to the Slack user. |
| 35 | |
| 36 | This exception is caught by the centralized error handler in SlackManager, |
| 37 | which logs the error and sends an appropriate message to the user. |
| 38 | |
| 39 | Usage: |
| 40 | raise SlackError(SlackErrorCode.USER_NOT_AUTHENTICATED, |
| 41 | message_kwargs={'login_link': link}) |
| 42 | """ |
| 43 | |
| 44 | def __init__( |
| 45 | self, |
| 46 | code: SlackErrorCode, |
| 47 | message_kwargs: dict[str, Any] | None = None, |
| 48 | log_context: dict[str, Any] | None = None, |
| 49 | ): |
| 50 | """Initialize a SlackError. |
| 51 | |
| 52 | Args: |
| 53 | code: The error code identifying the type of error |
| 54 | message_kwargs: Kwargs for formatting the user message |
| 55 | (e.g., {'login_link': '...'}) |
| 56 | log_context: Additional context for structured logging |
| 57 | """ |
| 58 | self.code = code |
| 59 | self.message_kwargs = message_kwargs or {} |
| 60 | self.log_context = log_context or {} |
| 61 | super().__init__(f'{code.value}: {code.name}') |
| 62 | |
| 63 | def get_user_message(self) -> str: |
| 64 | """Get the user-facing message for this error.""" |
| 65 | return get_user_message(self.code, **self.message_kwargs) |
| 66 | |
| 67 | |
| 68 | # Centralized user-facing messages |
no outgoing calls