From d6ccab417e282d8f363f42e8efe10cadb0d3ce3c Mon Sep 17 00:00:00 2001 From: Johnny Sequeira Date: Wed, 27 Nov 2024 13:20:09 -0600 Subject: [PATCH 1/2] Fixing misleading error message by no network available --- qfieldsync/core/cloud_api.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/qfieldsync/core/cloud_api.py b/qfieldsync/core/cloud_api.py index 35363e4e..6f70d3ba 100644 --- a/qfieldsync/core/cloud_api.py +++ b/qfieldsync/core/cloud_api.py @@ -688,6 +688,11 @@ def _on_avatar_download_finished(self, reply: QNetworkReply, filename: str) -> N self.avatar_success.emit() def get_last_login_error(self) -> str: + try: + requests.get(self.url, timeout=5) + except requests.ConnectionError: + return self.tr("No internet connection. Check your connection.") + if self.has_token(): return "" @@ -704,10 +709,9 @@ def get_last_login_error(self) -> str: if not error_str: error_str = self.tr("Sign in failed.") - html = '{}?'.format( - self.tr("Forgot password") + html = '{}?'.format( + self.url, self.tr("Forgot password") ) - return self.tr("{}. {}").format(error_str, html) def _clear_cloud_cookies(self, url: QUrl) -> None: From 68d001237a569ddbd7fa44dcb46857be5ff0a1f9 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 2 Dec 2024 02:37:41 +0200 Subject: [PATCH 2/2] Show "Check your internet" connection when there is not internet --- qfieldsync/core/cloud_api.py | 42 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/qfieldsync/core/cloud_api.py b/qfieldsync/core/cloud_api.py index 6f70d3ba..03b04cfa 100644 --- a/qfieldsync/core/cloud_api.py +++ b/qfieldsync/core/cloud_api.py @@ -688,31 +688,45 @@ def _on_avatar_download_finished(self, reply: QNetworkReply, filename: str) -> N self.avatar_success.emit() def get_last_login_error(self) -> str: - try: - requests.get(self.url, timeout=5) - except requests.ConnectionError: - return self.tr("No internet connection. Check your connection.") - if self.has_token(): return "" + suggest_forgotten_password = True error_str = "" + if self._login_error: - http_code = self._login_error.httpCode - if http_code and http_code >= 500: - error_str = self.tr("Server error {}").format(http_code) - elif http_code is None or (http_code >= 400 and http_code < 500): - error_str = str(self._login_error) + reply = self._login_error.reply + + if ( + reply.error() == QNetworkReply.HostNotFoundError + # network unreachable goes here + or reply.error() == QNetworkReply.UnknownNetworkError + ): + error_str = self.tr( + "Failed to connect to {}. Check your internet connection.".format( + self.url + ) + ) + suggest_forgotten_password = False + else: + http_code = self._login_error.httpCode + + if http_code and http_code >= 500: + error_str = self.tr("Server error {}").format(http_code) + elif http_code is None or (http_code >= 400 and http_code < 500): + error_str = str(self._login_error) error_str = strip_html(error_str).strip() if not error_str: error_str = self.tr("Sign in failed.") - html = '{}?'.format( - self.url, self.tr("Forgot password") - ) - return self.tr("{}. {}").format(error_str, html) + if suggest_forgotten_password: + error_str += ' {}?'.format( + self.url, self.tr("Forgot password") + ) + + return error_str def _clear_cloud_cookies(self, url: QUrl) -> None: """When the CSRF_TOKEN cookie is present and the plugin is reloaded, the token has expired"""