From 91f0d76c8a4d6affecb1f41529b138ccf1fb051d Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 8 Feb 2019 10:50:17 +0100 Subject: [PATCH] Fix crash when user was logged in but there was no internet connection on boot --- cura/OAuth2/AuthorizationHelpers.py | 2 +- cura/OAuth2/AuthorizationService.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cura/OAuth2/AuthorizationHelpers.py b/cura/OAuth2/AuthorizationHelpers.py index 762d0db069..87b8c45d6d 100644 --- a/cura/OAuth2/AuthorizationHelpers.py +++ b/cura/OAuth2/AuthorizationHelpers.py @@ -85,7 +85,7 @@ class AuthorizationHelpers: token_request = requests.get("{}/check-token".format(self._settings.OAUTH_SERVER_URL), headers = { "Authorization": "Bearer {}".format(access_token) }) - except ConnectionError: + except requests.exceptions.ConnectionError: # Connection was suddenly dropped. Nothing we can do about that. Logger.logException("e", "Something failed while attempting to parse the JWT token") return None diff --git a/cura/OAuth2/AuthorizationService.py b/cura/OAuth2/AuthorizationService.py index 1e98dc9cee..fc004e5e0d 100644 --- a/cura/OAuth2/AuthorizationService.py +++ b/cura/OAuth2/AuthorizationService.py @@ -4,6 +4,8 @@ import json import webbrowser from typing import Optional, TYPE_CHECKING from urllib.parse import urlencode +import requests.exceptions + from UM.Logger import Logger from UM.Signal import Signal @@ -51,7 +53,11 @@ class AuthorizationService: def getUserProfile(self) -> Optional["UserProfile"]: if not self._user_profile: # If no user profile was stored locally, we try to get it from JWT. - self._user_profile = self._parseJWT() + try: + self._user_profile = self._parseJWT() + except requests.exceptions.ConnectionError: + # Unable to get connection, can't login. + return None if not self._user_profile and self._auth_data: # If there is still no user profile from the JWT, we have to log in again.