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

Code before:
class OAuth2RefreshTokenError(ClientResponseError, IntegrationError):
    """Error to indicate that the OAuth 2.0 flow could not refresh token."""

    def __init__(
        self,
        *,
        request_info: RequestInfo,
        history: tuple[ClientResponse, ...] = (),
        status: int = 0,
        message: str = "OAuth 2.0 token refresh failed",
        headers: MultiMapping[str] | None = None,
    ) -> None:
        """Initialize OAuth2RefreshTokenFailed."""
        ClientResponseError.__init__(
            self,
            request_info=request_info,
            history=history,
            status=status,
            message=message,
            headers=headers,
        )
        IntegrationError.__init__(self, message)


class OAuth2RefreshTokenTransientError(OAuth2RefreshTokenError):
    """Error to indicate flow could not refresh token, but it's recoverable."""


class OAuth2RefreshTokenReauthError(OAuth2RefreshTokenError):
    """Error to indicate the flow could not refresh token, but not recoverable and re-authentication is required."""


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

Review comment (suggestion):
```suggestion
    """Recoverable error to indicate flow could not refresh token."""
```

Code after:
class OAuth2TokenRequestError(ClientResponseError, HomeAssistantError):
    """Error to indicate that the OAuth 2.0 flow could not refresh token."""

    def __init__(
        self,
        *,
        request_info: RequestInfo,
        history: tuple[ClientResponse, ...] = (),
        status: int = 0,
        message: str = "OAuth 2.0 token refresh failed",
        headers: MultiMapping[str] | None = None,
        domain: str,
    ) -> None:
        """Initialize OAuth2RefreshTokenFailed."""
        ClientResponseError.__init__(
            self,
            request_info=request_info,
            history=history,
            status=status,
            message=message,
            headers=headers,
        )
        HomeAssistantError.__init__(self)
        self.domain = domain
        self.translation_domain = "homeassistant"
        self.translation_key = "oauth2_helper_refresh_failed"
        self.translation_placeholders = {"domain": domain}
        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)