diff --git a/openhands_cli/auth/api_client.py b/openhands_cli/auth/api_client.py index 23029563c..e201a1d44 100644 --- a/openhands_cli/auth/api_client.py +++ b/openhands_cli/auth/api_client.py @@ -327,14 +327,22 @@ async def fetch_user_data_after_oauth( # Fetch user settings console_print("• Getting user settings...", style=OPENHANDS_THEME.secondary) - settings = await client.get_user_settings() - - if settings: - _print_settings_summary(settings) - else: + settings: dict[str, Any] | None + try: + settings = await client.get_user_settings() + except ApiClientError as e: + settings = None console_print( - " ! No user settings available", style=OPENHANDS_THEME.warning + f" ! Could not fetch user settings: {e}", + style=OPENHANDS_THEME.warning, ) + else: + if settings: + _print_settings_summary(settings) + else: + console_print( + " ! No user settings available", style=OPENHANDS_THEME.warning + ) user_data = { "llm_api_key": llm_api_key, diff --git a/tests/auth/test_api_client.py b/tests/auth/test_api_client.py index f15f557b8..84cab526c 100644 --- a/tests/auth/test_api_client.py +++ b/tests/auth/test_api_client.py @@ -306,6 +306,33 @@ async def test_fetch_user_data_after_oauth_no_settings(self): expected_result = {"llm_api_key": "llm-key-123", "settings": None} assert result == expected_result + @pytest.mark.asyncio + async def test_fetch_user_data_after_oauth_settings_api_error_is_nonfatal(self): + """Settings sync failures should not fail the completed login flow.""" + server_url = "https://api.example.com" + api_key = "test-api-key" + + with patch( + "openhands_cli.auth.api_client.OpenHandsApiClient" + ) as mock_client_class: + with patch( + "openhands_cli.auth.api_client.create_and_save_agent_configuration" + ) as mock_create_and_save: + with patch("openhands_cli.auth.api_client.console_print"): + mock_client = AsyncMock() + mock_client_class.return_value = mock_client + + mock_client.get_llm_api_key.return_value = "llm-key-123" + mock_client.get_user_settings.side_effect = ApiClientError( + "Request to '/api/v1/settings' returned a non-JSON response" + ) + + result = await fetch_user_data_after_oauth(server_url, api_key) + + expected_result = {"llm_api_key": "llm-key-123", "settings": None} + assert result == expected_result + mock_create_and_save.assert_not_called() + @pytest.mark.asyncio async def test_fetch_user_data_after_oauth_agent_creation_error(self): """Test user data fetching when agent creation fails."""