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

Code before:
                    history=err.history,
                    status=err.status,
                    message=err.message,
                    headers=err.headers,
                    domain=self._domain,
                ) from err
            if 400 <= err.status <= 499:
                # Non-recoverable error
                raise OAuth2TokenRequestReauthError(
                    request_info=err.request_info,
                    history=err.history,
                    status=err.status,
                    message=err.message,
                    headers=err.headers,
                    domain=self._domain,
                ) from err

            raise OAuth2TokenRequestError(
                request_info=err.request_info,
                history=err.history,
                status=err.status,
                message=err.message,
                headers=err.headers,
                domain=self._domain,
            ) from err
        except ClientError as err:
            raise HomeAssistantError(
                f"Error requesting OAuth token for {self._domain}. Error: {err}"
            ) from err

        return cast(dict, await resp.json())


class LocalOAuth2ImplementationWithPkce(LocalOAuth2Implementation):
    """Local OAuth2 implementation with PKCE."""

    def __init__(
        self,
        hass: HomeAssistant,
        domain: str,
        client_id: str,
        authorize_url: str,
        token_url: str,
        client_secret: str = "",
        code_verifier_length: int = 128,
    ) -> None:
        """Initialize local auth implementation."""
        super().__init__(
            hass,
            domain,
            client_id,

Review comment (suggestion):
I think we should let this bubble up so we keep the change less breaking and the scope of the change smaller. We can tackle this exception later separately if wanted.

It's not as impactful to handle it differently since it is already handled correctly by the update coordinator. Ie it will cause the config entry to try again if the coordinator receives this exception during config entry setup, and after config entry setup, the coordinator will set `last_update_success` to False.

Code after:
                    history=err.history,
                    status=err.status,
                    message=err.message,
                    headers=err.headers,
                    domain=self._domain,
                ) from err

            raise OAuth2TokenRequestError(
                request_info=err.request_info,
                history=err.history,
                status=err.status,
                message=err.message,
                headers=err.headers,
                domain=self._domain,
            ) from err

        return cast(dict, await resp.json())


class LocalOAuth2ImplementationWithPkce(LocalOAuth2Implementation):
    """Local OAuth2 implementation with PKCE."""

    def __init__(
        self,
        hass: HomeAssistant,
        domain: str,
        client_id: str,
        authorize_url: str,
        token_url: str,
        client_secret: str = "",
        code_verifier_length: int = 128,
    ) -> None:
        """Initialize local auth implementation."""
        super().__init__(
            hass,
            domain,
            client_id,
            client_secret,
            authorize_url,
            token_url,
        )

        # Generate code verifier
        self.code_verifier = LocalOAuth2ImplementationWithPkce.generate_code_verifier(
            code_verifier_length
        )

    @property
    def extra_authorize_data(self) -> dict:
        """Extra data that needs to be appended to the authorize url.