Skip to content

Commit

Permalink
Merge pull request #629 from opengisch/QF-4953-more-explicit-to-the-u…
Browse files Browse the repository at this point in the history
…ser-when-there-is-no-internet

Fixing misleading error message by no network available
  • Loading branch information
suricactus authored Dec 3, 2024
2 parents be53ae5 + 68d0012 commit 0589e54
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions qfieldsync/core/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,24 +691,42 @@ def get_last_login_error(self) -> str:
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 = '<a href="https://app.qfield.cloud/accounts/password/reset/">{}?</a>'.format(
self.tr("Forgot password")
)
if suggest_forgotten_password:
error_str += ' <a href="{}accounts/password/reset/">{}?</a>'.format(
self.url, self.tr("Forgot password")
)

return self.tr("{}. {}").format(error_str, html)
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"""
Expand Down

0 comments on commit 0589e54

Please sign in to comment.