diff --git a/securedrop_client/logic.py b/securedrop_client/logic.py index aa9298f402..3afc2aa32b 100644 --- a/securedrop_client/logic.py +++ b/securedrop_client/logic.py @@ -321,7 +321,8 @@ def call_api(self, new_api_thread.start() def on_queue_paused(self) -> None: - self.gui.update_error_status(_('The SecureDrop server cannot be reached.'), duration=0) + self.gui.update_error_status( + _('The SecureDrop server cannot be reached. Trying to reconnect...'), duration=0) self.show_last_sync_timer.start(TIME_BETWEEN_SHOWING_LAST_SYNC_MS) def resume_queues(self) -> None: @@ -461,6 +462,9 @@ def on_sync_failure(self, result: Exception) -> None: self.invalidate_token() self.logout() self.gui.show_login(error=_('Your session expired. Please log in again.')) + elif isinstance(result, (RequestTimeoutError, ServerConnectionError)): + self.gui.update_error_status( + _('The SecureDrop server cannot be reached. Trying to reconnect...'), duration=0) def show_last_sync(self): """ diff --git a/tests/test_logic.py b/tests/test_logic.py index c452834e24..187f016bcc 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -427,6 +427,38 @@ def test_Controller_on_sync_failure_due_to_invalid_token(homedir, config, mocker co.gui.show_login.assert_called_once_with(error='Your session expired. Please log in again.') +def test_Controller_on_sync_failure_due_to_request_timeout(homedir, config, mocker, session_maker): + """ + If the sync fails because of a request timeout, make sure to show an error message. + """ + gui = mocker.MagicMock() + co = Controller('http://localhost', gui, session_maker, homedir) + co.logout = mocker.MagicMock() + co.gui = mocker.MagicMock() + co.gui.update_error_status = mocker.MagicMock() + + co.on_sync_failure(RequestTimeoutError()) + + co.gui.update_error_status.assert_called_once_with( + 'The SecureDrop server cannot be reached. Trying to reconnect...', duration=0) + + +def test_Controller_on_sync_failure_due_to_connect_timeout(homedir, config, mocker, session_maker): + """ + If the sync fails because of a connect timeout, make sure to show an error message. + """ + gui = mocker.MagicMock() + co = Controller('http://localhost', gui, session_maker, homedir) + co.logout = mocker.MagicMock() + co.gui = mocker.MagicMock() + co.gui.update_error_status = mocker.MagicMock() + + co.on_sync_failure(ServerConnectionError()) + + co.gui.update_error_status.assert_called_once_with( + 'The SecureDrop server cannot be reached. Trying to reconnect...', duration=0) + + def test_Controller_on_sync_success(homedir, config, mocker): """ If there's a result to syncing, then update local storage. @@ -1489,7 +1521,7 @@ def test_Controller_on_queue_paused(homedir, config, mocker, session_maker): co.show_last_sync_timer = mocker.MagicMock() co.on_queue_paused() mock_gui.update_error_status.assert_called_once_with( - 'The SecureDrop server cannot be reached.', duration=0) + 'The SecureDrop server cannot be reached. Trying to reconnect...', duration=0) co.show_last_sync_timer.start.assert_called_once_with(TIME_BETWEEN_SHOWING_LAST_SYNC_MS)