Repository: home-assistant/core
File: homeassistant/exceptions.py (Python)

Code before:
        self.generate_message = True


class OAuth2RefreshTokenTransientError(OAuth2RefreshTokenError):
    """Recoverable error to indicate flow could not refresh token."""

    def __init__(self, *, domain: str, **kwargs: Any) -> None:
        """Initialize OAuth2RefreshTokenTransientError."""
        super().__init__(domain=domain, **kwargs)
        self.translation_domain = "homeassistant"
        self.translation_key = "oauth2_helper_refresh_transient"
        self.translation_placeholders = {"domain": domain}
        self.generate_message = True


class OAuth2RefreshTokenReauthError(OAuth2RefreshTokenError):
    """Non recoverable error to indicate the flow could not refresh token.

    Re-authentication is required.
    """

    def __init__(self, *, domain: str, **kwargs: Any) -> None:
        """Initialize OAuth2RefreshTokenTransientError."""
        super().__init__(domain=domain, **kwargs)
        self.translation_domain = "homeassistant"
        self.translation_key = "oauth2_helper_refresh_failed"
        self.translation_placeholders = {"domain": domain}
        self.generate_message = True


class InvalidStateError(HomeAssistantError):
    """When an invalid state is encountered."""


class Unauthorized(HomeAssistantError):
    """When an action is unauthorized."""

    def __init__(
        self,
        context: Context | None = None,
        user_id: str | None = None,
        entity_id: str | None = None,
        config_entry_id: str | None = None,
        perm_category: str | None = None,
        permission: str | None = None,
    ) -> None:
        """Unauthorized error."""
        super().__init__(self.__class__.__name__)
        self.context = context

        if user_id is None and context is not None:

Review comment (security):
```suggestion
        self.translation_key = "oauth2_helper_reauth_required"
```

Code after:
        self.generate_message = True


class OAuth2TokenRequestTransientError(OAuth2TokenRequestError):
    """Recoverable error to indicate flow could not refresh token."""

    def __init__(self, *, domain: str, **kwargs: Any) -> None:
        """Initialize OAuth2RefreshTokenTransientError."""
        super().__init__(domain=domain, **kwargs)
        self.translation_domain = "homeassistant"
        self.translation_key = "oauth2_helper_refresh_transient"
        self.translation_placeholders = {"domain": domain}
        self.generate_message = True


class OAuth2TokenRequestReauthError(OAuth2TokenRequestError):
    """Non recoverable error to indicate the flow could not refresh token.

    Re-authentication is required.
    """

    def __init__(self, *, domain: str, **kwargs: Any) -> None:
        """Initialize OAuth2RefreshTokenReauthError."""
        super().__init__(domain=domain, **kwargs)
        self.translation_domain = "homeassistant"
        self.translation_key = "oauth2_helper_reauth_required"
        self.translation_placeholders = {"domain": domain}
        self.generate_message = True


class InvalidStateError(HomeAssistantError):
    """When an invalid state is encountered."""


class Unauthorized(HomeAssistantError):
    """When an action is unauthorized."""

    def __init__(
        self,
        context: Context | None = None,
        user_id: str | None = None,
        entity_id: str | None = None,
        config_entry_id: str | None = None,
        perm_category: str | None = None,
        permission: str | None = None,
    ) -> None:
        """Unauthorized error."""
        super().__init__(self.__class__.__name__)
        self.context = context

        if user_id is None and context is not None: