diff --git a/aiogithubapi/device.py b/aiogithubapi/device.py index 8190fc2..4085701 100644 --- a/aiogithubapi/device.py +++ b/aiogithubapi/device.py @@ -21,7 +21,7 @@ GitHubRequestKwarg, HttpMethod, ) -from .exceptions import GitHubException +from .exceptions import GitHubAuthenticationException, GitHubException from .legacy.device import AIOGitHubAPIDeviceLogin as LegacyAIOGitHubAPIDeviceLogin from .models.base import GitHubBase from .models.device_login import GitHubLoginDeviceModel @@ -151,6 +151,14 @@ async def activation( }, ) + if ( + isinstance(response.data, str) + and "You have exceeded a secondary rate limit" in response.data + ): + raise GitHubAuthenticationException( + "Secondary rate limit exceeded, try again in 1 hour" + ) + if error := response.data.get("error"): self.logger.debug(response.data.get("error_description")) if error in (DeviceFlowError.AUTHORIZATION_PENDING, DeviceFlowError.SLOW_DOWN): diff --git a/tests/device/test_device_flow.py b/tests/device/test_device_flow.py index dd60d5b..64b25c6 100644 --- a/tests/device/test_device_flow.py +++ b/tests/device/test_device_flow.py @@ -2,6 +2,7 @@ # pylint: disable=missing-docstring,protected-access from datetime import datetime from unittest.mock import AsyncMock +from aiogithubapi.exceptions import GitHubAuthenticationException import pytest @@ -124,3 +125,13 @@ async def test_error_while_waiting( mock_response.mock_data = {"error": "any", "error_description": "Any error message"} with pytest.raises(GitHubException, match="Any error message"): await github_device_api.activation(device_code=DEVICE_CODE) + + +@pytest.mark.asyncio +async def test_secondary_rate_limit( + github_device_api: GitHubDeviceAPI, + mock_response: MockResponse, +): + mock_response.mock_data = "

You have exceeded a secondary rate limit.
" + with pytest.raises(GitHubAuthenticationException, match="Secondary rate limit exceeded"): + await github_device_api.activation(device_code=DEVICE_CODE) \ No newline at end of file